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

#375 in Authentication

Download history 23/week @ 2024-01-06 28/week @ 2024-01-13 28/week @ 2024-01-20 57/week @ 2024-01-27 53/week @ 2024-02-03 37/week @ 2024-02-10 80/week @ 2024-02-17 85/week @ 2024-02-24 31/week @ 2024-03-02 51/week @ 2024-03-09 50/week @ 2024-03-16 28/week @ 2024-03-23 132/week @ 2024-03-30 128/week @ 2024-04-06 74/week @ 2024-04-13 56/week @ 2024-04-20

392 downloads per month
Used in 2 crates

MIT license

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

~5.5–7.5MB
~222K SLoC