2023-04-29 13:39:17 -04:00
|
|
|
use totp_rs::{Algorithm, TOTP, LabeledTOTP};
|
2022-08-06 11:49:40 -04:00
|
|
|
|
2022-08-09 05:05:36 -04:00
|
|
|
fn main() {
|
|
|
|
let totp = TOTP::new(
|
|
|
|
Algorithm::SHA1,
|
|
|
|
6,
|
|
|
|
1,
|
|
|
|
30,
|
2022-11-01 23:14:18 -04:00
|
|
|
"my-secret".as_bytes().to_vec(),
|
2022-10-05 05:55:37 -04:00
|
|
|
)
|
2023-04-29 13:39:17 -04:00
|
|
|
.and_then(|totp| LabeledTOTP::new(
|
|
|
|
totp,
|
|
|
|
"Github".to_string(),
|
|
|
|
"constantoine@github.com".to_string(),
|
|
|
|
))
|
2022-10-05 05:55:37 -04:00
|
|
|
.unwrap();
|
2022-08-06 11:49:40 -04:00
|
|
|
|
|
|
|
loop {
|
|
|
|
println!(
|
|
|
|
"code {}\t ttl {}\t valid until: {}",
|
|
|
|
totp.generate_current().unwrap(),
|
|
|
|
totp.ttl().unwrap(),
|
|
|
|
totp.next_step_current().unwrap()
|
|
|
|
);
|
|
|
|
std::thread::sleep(std::time::Duration::from_secs(1));
|
|
|
|
}
|
|
|
|
}
|