Struct ootp::totp::Totp [−][src]
pub struct Totp<'a> {
pub hotp: Hotp<'a>,
pub digits: u32,
pub period: u64,
pub algorithm: &'a ShaTypes,
}
Expand description
The TOTP is a HOTP-based one-time password algorithm, with a time value as moving factor.
It takes four parameter. An Hotp
istance, the desired number of digits, a time period and the SHA algorithm.
Fields
hotp: Hotp<'a>
digits: u32
period: u64
algorithm: &'a ShaTypes
Implementations
TOTP instance constructor
This function returns a string of the one-time password
Example
use ootp::totp::{Totp, CreateOption};
let secret = "A strong shared secrett";
let totp = Totp::secret(
secret,
CreateOption::Default
);
let otp = totp.make(); // Generate a one-time password
println!("{}", otp); // Print the one-time password
This function returns a string of the one-time password, valid a period
from time
seconds since the UNIX epoch
Example
use ootp::totp::{Totp, CreateOption};
let secret = "A strong shared secrett";
let totp = Totp::secret(
secret,
CreateOption::Default
);
let otp = totp.make_time(59); // Generate a one-time password, valid a `DEFAULT_PERIOD from `59` seconds since the UNIX epoch
println!("{}", otp); // Print the one-time password
Returns a boolean indicating if the one-time password is valid.
Example #1
use ootp::totp::{Totp, CreateOption};
let secret = "A strong shared secret";
let totp = Totp::secret(
secret,
CreateOption::Default
);
let otp = totp.make(); // Generate a one-time password
let check = totp.check(otp.as_str(), None);
Example #2
use ootp::totp::{Totp, CreateOption};
let secret = "A strong shared secret";
let totp = Totp::secret(
secret,
CreateOption::Digits(8)
);
let otp = totp.make(); // Generate a one-time password
let check = totp.check(otp.as_str(), Some(42));