6 stable releases

2.0.1 Oct 30, 2023
2.0.0 May 20, 2022
1.1.0 May 18, 2022
1.0.3 May 28, 2021
1.0.1 Aug 21, 2020

#54 in Authentication

Download history 2788/week @ 2024-07-21 3288/week @ 2024-07-28 2486/week @ 2024-08-04 3129/week @ 2024-08-11 2527/week @ 2024-08-18 2889/week @ 2024-08-25 2706/week @ 2024-09-01 2690/week @ 2024-09-08 2070/week @ 2024-09-15 2624/week @ 2024-09-22 3535/week @ 2024-09-29 3552/week @ 2024-10-06 2938/week @ 2024-10-13 2911/week @ 2024-10-20 3475/week @ 2024-10-27 3285/week @ 2024-11-03

12,887 downloads per month
Used in 16 crates (10 directly)

MIT license

11KB
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

~550KB
~12K SLoC