4 stable releases

1.0.3 May 28, 2021
1.0.2 Nov 19, 2020
1.0.1 Aug 21, 2020

#61 in Authentication

Download history 749/week @ 2021-10-05 1005/week @ 2021-10-12 1226/week @ 2021-10-19 1047/week @ 2021-10-26 791/week @ 2021-11-02 985/week @ 2021-11-09 679/week @ 2021-11-16 489/week @ 2021-11-23 648/week @ 2021-11-30 679/week @ 2021-12-07 935/week @ 2021-12-14 609/week @ 2021-12-21 725/week @ 2021-12-28 1117/week @ 2022-01-04 890/week @ 2022-01-11 750/week @ 2022-01-18

3,539 downloads per month
Used in 3 crates

MIT license

10KB
109 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

~445KB
~10K SLoC