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

#79 in Authentication

Download history 3289/week @ 2024-10-23 3302/week @ 2024-10-30 3406/week @ 2024-11-06 3797/week @ 2024-11-13 3026/week @ 2024-11-20 2993/week @ 2024-11-27 4478/week @ 2024-12-04 4639/week @ 2024-12-11 3503/week @ 2024-12-18 1888/week @ 2024-12-25 3283/week @ 2025-01-01 4201/week @ 2025-01-08 4180/week @ 2025-01-15 4753/week @ 2025-01-22 4182/week @ 2025-01-29 3966/week @ 2025-02-05

17,621 downloads per month
Used in 17 crates (11 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

~555KB
~12K SLoC