14 releases

0.5.1 Aug 28, 2024
0.4.1 Aug 23, 2019
0.4.0 Jul 29, 2019
0.2.7 Oct 29, 2018
0.2.1 Jun 27, 2015

#147 in Authentication

Download history 61/week @ 2024-07-14 39/week @ 2024-07-21 59/week @ 2024-07-28 72/week @ 2024-08-04 114/week @ 2024-08-11 275/week @ 2024-08-18 626/week @ 2024-08-25 275/week @ 2024-09-01 297/week @ 2024-09-08 274/week @ 2024-09-15 270/week @ 2024-09-22 219/week @ 2024-09-29 206/week @ 2024-10-06 315/week @ 2024-10-13 447/week @ 2024-10-20 352/week @ 2024-10-27

1,353 downloads per month
Used in 2 crates

MIT license

10KB
115 lines

otpauth-rs

CI Crates.io

Two-step verification of HOTP/TOTP for Rust.

Installation

Add it to your Cargo.toml:

[dependencies]
otpauth = "0.5"

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–12MB
~233K SLoC