1use totp_rs::{Algorithm, TOTP};
2
3#[cfg(not(feature = "otpauth"))]
4fn main() {
5 let totp = TOTP::new(Algorithm::SHA1, 6, 1, 30, "my-secret".as_bytes().to_vec()).unwrap();
6
7 loop {
8 println!(
9 "code {}\t ttl {}\t valid until: {}",
10 totp.generate_current().unwrap(),
11 totp.ttl().unwrap(),
12 totp.next_step_current().unwrap()
13 );
14 std::thread::sleep(std::time::Duration::from_secs(1));
15 }
16}
17
18#[cfg(feature = "otpauth")]
19fn main() {
20 let totp = TOTP::new(
21 Algorithm::SHA1,
22 6,
23 1,
24 30,
25 "my-secret".as_bytes().to_vec(),
26 Some("Github".to_string()),
27 "constantoine@github.com".to_string(),
28 )
29 .unwrap();
30
31 loop {
32 println!(
33 "code {}\t ttl {}\t valid until: {}",
34 totp.generate_current().unwrap(),
35 totp.ttl().unwrap(),
36 totp.next_step_current().unwrap()
37 );
38 std::thread::sleep(std::time::Duration::from_secs(1));
39 }
40}