Crates.io | otpauth |
lib.rs | otpauth |
version | 0.5.1 |
source | src |
created_at | 2015-05-28 14:08:58.330907 |
updated_at | 2024-08-28 10:51:59.749235 |
description | Two-step verification of HOTP/TOTP for Rust |
homepage | https://github.com/messense/otpauth-rs |
repository | https://github.com/messense/otpauth-rs.git |
max_upload_size | |
id | 2237 |
size | 12,849 |
Two-step verification of HOTP/TOTP for Rust.
Add it to your Cargo.toml
:
[dependencies]
otpauth = "0.5"
use otpauth::HOTP;
fn main() {
let auth = HOTP::new("python");
let code = auth.generate(4);
assert_eq!(true, auth.verify(code, 0, 100));
}
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));
}
This work is released under the MIT license. A copy of the license is provided in the LICENSE file.