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

#172 in Authentication

Download history 615/week @ 2025-03-12 548/week @ 2025-03-19 613/week @ 2025-03-26 472/week @ 2025-04-02 535/week @ 2025-04-09 831/week @ 2025-04-16 631/week @ 2025-04-23 567/week @ 2025-04-30 886/week @ 2025-05-07 794/week @ 2025-05-14 1115/week @ 2025-05-21 409/week @ 2025-05-28 382/week @ 2025-06-04 544/week @ 2025-06-11 717/week @ 2025-06-18 381/week @ 2025-06-25

2,125 downloads per month
Used in 3 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–13MB
~244K SLoC