12 unstable releases (3 breaking)

0.4.1 Aug 23, 2019
0.4.0 Jul 29, 2019
0.3.0 Jul 29, 2019
0.2.7 Oct 29, 2018
0.2.1 Jun 27, 2015

#396 in Authentication

Download history 73/week @ 2023-11-22 69/week @ 2023-11-29 67/week @ 2023-12-06 93/week @ 2023-12-13 54/week @ 2023-12-20 34/week @ 2023-12-27 14/week @ 2024-01-03 30/week @ 2024-01-10 27/week @ 2024-01-17 45/week @ 2024-01-24 45/week @ 2024-01-31 45/week @ 2024-02-07 78/week @ 2024-02-14 67/week @ 2024-02-21 66/week @ 2024-02-28 26/week @ 2024-03-06

240 downloads per month
Used in 2 crates

MIT license

11KB
114 lines

otpauth-rs

Build Status Build status Coverage Status Crates.io

Two-step verification of HOTP/TOTP for Rust.

Installation

Add it to your Cargo.toml:

[dependencies]
otpauth = "0.3"

Examples

HOTP example

use otpauth::HOTP;


fn main() {
    let auth = HOTP::new("python");
    let code = auth.generate(4);
    assert_eq!(true, auth.verify(code, 0, 100));
}

TOTP example

use std::time::{SystemTime, UNIX_EPOCH};

use otpauth::TOTP;


fn main() {
    let auth = TOTP::new("python");
    let timestamp1 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
    let code = auth.generate(30, timestamp1);
    let timestamp2 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
    assert_eq!(true, auth.verify(code, 30, timestamp2));
}

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

Dependencies

~5.5–7.5MB
~221K SLoC