totp-lite

Crates.iototp-lite
lib.rstotp-lite
version2.0.1
sourcesrc
created_at2020-08-21 01:05:22.510379
updated_at2023-10-30 02:22:42.765807
descriptionA simple, correct TOTP library.
homepagehttps://github.com/fosskers/totp-lite
repositoryhttps://github.com/fosskers/totp-lite
max_upload_size
id278970
size25,444
Colin Woodbury (fosskers)

documentation

README

Workflow Status

totp-lite

A simple, correct TOTP library.

Time-based One-time Passwords are a useful way to authenticate a client, since a valid password expires long before it could ever be guessed by an attacker. This library provides an implementation of TOTP that matches its specification RFC6238, along with a simple interface.

Usage

The totp function is likely what you need. It uses the default time step of 30 seconds and produces 8 digits of output:

use std::time::{SystemTime, UNIX_EPOCH};
use totp_lite::{totp, Sha512};

// Negotiated between you and the authenticating service.
let password: &[u8] = b"secret";

// The number of seconds since the Unix Epoch.
let seconds: u64 = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();

// Specify the desired Hash algorithm via a type parameter.
// `Sha1` and `Sha256` are also available.
let result: String = totp::<Sha512>(password, seconds);
assert_eq!(8, result.len());

For full control over how the algorithm is configured, consider totp_custom.

Resources

License: MIT

Commit count: 50

cargo fmt