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

#1 in #otpauth

Download history 121/week @ 2023-02-08 135/week @ 2023-02-15 73/week @ 2023-02-22 70/week @ 2023-03-01 115/week @ 2023-03-08 46/week @ 2023-03-15 22/week @ 2023-03-22 53/week @ 2023-03-29 55/week @ 2023-04-05 102/week @ 2023-04-12 70/week @ 2023-04-19 91/week @ 2023-04-26 125/week @ 2023-05-03 116/week @ 2023-05-10 52/week @ 2023-05-17 33/week @ 2023-05-24

330 downloads per month
Used in auth-o-tron

MIT license

10KB
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

~4.5–6.5MB
~183K SLoC