5 stable releases

2.0.0 May 20, 2022
1.1.0 May 18, 2022
1.0.3 May 28, 2021
1.0.2 Nov 19, 2020
1.0.1 Aug 21, 2020

#35 in Authentication

Download history 1637/week @ 2022-10-15 1505/week @ 2022-10-22 1622/week @ 2022-10-29 1891/week @ 2022-11-05 1876/week @ 2022-11-12 1332/week @ 2022-11-19 1851/week @ 2022-11-26 1608/week @ 2022-12-03 1611/week @ 2022-12-10 1239/week @ 2022-12-17 1065/week @ 2022-12-24 1458/week @ 2022-12-31 2416/week @ 2023-01-07 2263/week @ 2023-01-14 2258/week @ 2023-01-21 2533/week @ 2023-01-28

9,760 downloads per month
Used in 7 crates (6 directly)

MIT license

10KB
130 lines

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

Dependencies

~430KB