[][src]Function libotp::totp

pub fn totp(
    secret: &str,
    digits: u32,
    time_step: u64,
    time_start: u64
) -> Option<u32>

Time based One Time Password function

Arguments

  • secret - base32 encoded shared-secret.
  • digits - Desired OTP length in digits. 6+ is recommended.
  • time_step - Time frame for OTP is seconds.
  • time_start - Beginning of time for this TOTP.

Example Usage

use libotp::totp;
const MY_SECRET: &str = "VMNW2EC7X3OCJHITBVSVZW5MVCUIL5SR";

fn main() {
    match totp(MY_SECRET, 6, 30, 0) {
        Some(otp) => {
            println!("Your current OTP is: {:06}", otp);
        },
        None => {
            println!("Failed to calculate OTP.");
        }
    }
}