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

#34 in Authentication

Download history 2262/week @ 2024-03-14 2483/week @ 2024-03-21 2137/week @ 2024-03-28 2094/week @ 2024-04-04 1946/week @ 2024-04-11 2449/week @ 2024-04-18 2827/week @ 2024-04-25 3432/week @ 2024-05-02 3580/week @ 2024-05-09 3582/week @ 2024-05-16 2896/week @ 2024-05-23 3680/week @ 2024-05-30 2876/week @ 2024-06-06 2962/week @ 2024-06-13 3496/week @ 2024-06-20 2028/week @ 2024-06-27

11,875 downloads per month
Used in 14 crates (9 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

~535KB
~11K SLoC