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

#279 in Authentication

Download history 640/week @ 2025-10-08 713/week @ 2025-10-15 734/week @ 2025-10-22 1135/week @ 2025-10-29 1087/week @ 2025-11-05 532/week @ 2025-11-12 611/week @ 2025-11-19 657/week @ 2025-11-26 1322/week @ 2025-12-03 1202/week @ 2025-12-10 1930/week @ 2025-12-17 689/week @ 2025-12-24 343/week @ 2025-12-31 843/week @ 2026-01-07 1002/week @ 2026-01-14 937/week @ 2026-01-21

3,388 downloads per month
Used in 5 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–16MB
~237K SLoC