Edit

thodg/totp-rs/examples/ttl.rs

Branch :

  • Show log

    Commit

  • Author : constantoine
    Date : 2022-08-09 11:05:36
    Hash : cd903afb
    Message : Make otpauth fields only appear with otpauth feature Signed-off-by: constantoine <cleo.rebert-ext@treezor.com>

  • examples/ttl.rs
  • use totp_rs::{Algorithm, TOTP};
    
    #[cfg(not(feature = "otpauth"))]
    fn main() {
        let totp = TOTP::new(
            Algorithm::SHA1,
            6,
            1,
            30,
            "my-secret".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));
        }
    }
    
    
    #[cfg(feature = "otpauth")]
    fn main() {
        let totp = TOTP::new(
            Algorithm::SHA1,
            6,
            1,
            30,
            "my-secret".to_string(),
            Some("Github".to_string()),
            "constantoine@github.com".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));
        }
    }