2022-08-06 11:31:11 -04:00
|
|
|
use totp_rs::{Rfc6238, TOTP};
|
|
|
|
|
2022-08-09 05:05:36 -04:00
|
|
|
#[cfg(feature = "otpauth")]
|
2022-10-05 05:55:37 -04:00
|
|
|
fn main() {
|
2022-11-01 23:14:18 -04:00
|
|
|
let mut rfc = Rfc6238::with_defaults("totp-sercret-123".as_bytes().to_vec()).unwrap();
|
2022-08-06 11:31:11 -04:00
|
|
|
|
|
|
|
// optional, set digits, issuer, account_name
|
|
|
|
rfc.digits(8).unwrap();
|
|
|
|
rfc.issuer("issuer".to_string());
|
|
|
|
rfc.account_name("user-account".to_string());
|
|
|
|
|
|
|
|
// create a TOTP from rfc
|
|
|
|
let totp = TOTP::from_rfc6238(rfc).unwrap();
|
|
|
|
let code = totp.generate_current().unwrap();
|
|
|
|
println!("code: {}", code);
|
|
|
|
}
|
2022-08-09 05:05:36 -04:00
|
|
|
|
|
|
|
#[cfg(not(feature = "otpauth"))]
|
2022-10-05 05:55:37 -04:00
|
|
|
fn main() {
|
|
|
|
let mut rfc = Rfc6238::with_defaults("totp-sercret-123").unwrap();
|
2022-08-09 05:05:36 -04:00
|
|
|
|
|
|
|
// optional, set digits, issuer, account_name
|
|
|
|
rfc.digits(8).unwrap();
|
|
|
|
|
|
|
|
// create a TOTP from rfc
|
|
|
|
let totp = TOTP::from_rfc6238(rfc).unwrap();
|
|
|
|
let code = totp.generate_current().unwrap();
|
|
|
|
println!("code: {}", code);
|
2022-10-05 05:55:37 -04:00
|
|
|
}
|