Function thotp::otp

source · []
pub fn otp(secret: &[u8], nonce: u64) -> Result<String, ThotpError>
Expand description

Uses HMAC-SHA-1 and the default digit length of 6 to generate a one time password.

The security of the OTP generated by this function is as recommended by the RFC and should be adequate for most intents and purposes. If you need finer control over how the inputs are hashed or the digit length, use the custom_otp feature flag which provides functions with more customizable parameters.

The secret is an arbitrary byte array (one can be generated with this crate’s generate_secret function) and the nonce is either a unix timestamp divided by the time step when dealing with TOTPs or a counter when dealing with HOTPs.

The default verification functions use this function to create a password to compare to their inputs.