Edit

thodg/totp-rs/examples/ttl.rs

Branch :

  • Show log

    Commit

  • Author : Steven Salaun
    Date : 2022-08-06 17:49:40
    Hash : 40196c5e
    Message : add `ttl` to TOTP

  • examples/ttl.rs
  • use totp_rs::{Algorithm, TOTP};
    
    fn main() {
        let totp = TOTP::new(
            Algorithm::SHA1,
            6,
            1,
            30,
            "my-secret".to_string(),
            None,
            "account".to_string(),
        ).unwrap();
    
        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));
        }
    }