add totp
This commit is contained in:
11
totp/Cargo.toml
Normal file
11
totp/Cargo.toml
Normal file
@@ -0,0 +1,11 @@
|
||||
[package]
|
||||
name = "totp"
|
||||
version = "0.1.0"
|
||||
authors = ["Hatter Jiang <jht5945@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
time = "0.1.42"
|
||||
otpauth = "0.2.7"
|
||||
13
totp/src/main.rs
Normal file
13
totp/src/main.rs
Normal file
@@ -0,0 +1,13 @@
|
||||
extern crate otpauth;
|
||||
extern crate time;
|
||||
|
||||
use otpauth::TOTP;
|
||||
|
||||
fn main() {
|
||||
let auth = TOTP::new("python");
|
||||
let timestamp1 = time::now().to_timespec().sec as usize;
|
||||
let code = auth.generate(30, timestamp1);
|
||||
let timestamp2 = time::now().to_timespec().sec as usize;
|
||||
println!("code: {}", code);
|
||||
assert_eq!(true, auth.verify(code, 30, timestamp2));
|
||||
}
|
||||
Reference in New Issue
Block a user