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

#114 in Authentication

Download history 298/week @ 2024-11-16 715/week @ 2024-11-23 299/week @ 2024-11-30 416/week @ 2024-12-07 216/week @ 2024-12-14 40/week @ 2024-12-21 44/week @ 2024-12-28 118/week @ 2025-01-04 201/week @ 2025-01-11 191/week @ 2025-01-18 199/week @ 2025-01-25 423/week @ 2025-02-01 484/week @ 2025-02-08 644/week @ 2025-02-15 750/week @ 2025-02-22 506/week @ 2025-03-01

2,500 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
~234K SLoC