Crate libotp [−] [src]
HMAC and Time-Based One-Time-Password implementations based on RFC4226 and RFC6238.
Examples
use libotp::{HOTP, TOTP}; const TOTP_STEP: u64 = 30; const OTP_DIGITS: u32 = 8; fn check_user_otp(user: User, guess: u32) -> bool { // get the shared secret from some database. let secret = user.get_totp_secret(); // create a HOTP instance & TOTP instance let hotp = HOTP::from_bin(secret).unwrap(); let totp = TOTP::new(hotp, TOTP_STEP, 0); // validate guess with TOTP return totp.validate(OTP_DIGITS, guess, 0); } fn get_user_otp(user: User) -> u32 { // get shared secret let secret = user.get_totp_secret(); return TOTP::new( HOTP::from_bin(secret).unwrap(), TOTP_STEP, 0).get_otp(OTP_DIGITS, 0); }
Structs
HOTP |
This is the secret that will be used to generate HMAC based one-time-passwords. |
TOTP |
Provides Time based One Time Passwords. |
Enums
HOTPAlgorithm |