#authentication #2fa #totp #hmac #otp

totp-rs

RFC-compliant TOTP implementation with ease of use as a goal and additionnal QoL features

17 releases (4 breaking)

0.6.3 Nov 2, 2020
0.6.2 Sep 12, 2020
0.6.1 Aug 9, 2020
0.5.0 Jul 3, 2020
0.2.5 Apr 25, 2020

#67 in Authentication

Download history 79/week @ 2020-08-06 52/week @ 2020-08-13 23/week @ 2020-08-20 27/week @ 2020-08-27 47/week @ 2020-09-03 14/week @ 2020-09-10 6/week @ 2020-09-17 14/week @ 2020-09-24 6/week @ 2020-10-01 20/week @ 2020-10-08 9/week @ 2020-10-15 24/week @ 2020-10-22 16/week @ 2020-10-29 49/week @ 2020-11-05 13/week @ 2020-11-12 8/week @ 2020-11-19

109 downloads per month

MIT license

13KB
170 lines

totp-rs

Build Status docs

This library permits the creation of 2FA authentification tokens per TOTP, the verification of said tokens, with configurable time skew, validity time of each token, algorithm and number of digits! Default features are kept as lightweight as possible to ensure small binaries and short compilation time

Features


qr

With optional feature "qr", you can use it to generate a base64 png qrcode

serde_support

With optional feature "serde_support", library-defined types will be Deserialize-able and Serialize-able

How to use


Add it to your Cargo.toml:

[dependencies]
totp-rs = "~0.6"

You can then do something like:

use std::time::SystemTime;
use totp_rs::{Algorithm, TOTP};

let totp = TOTP::new(
    Algorithm::SHA1,
    6,
    1,
    30,
    "supersecret",
);
let time = SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH).unwrap()
    .as_secs();
let url = totp.get_url("user@example.com", "my-org.com");
println!("{}", url);
let token = totp.generate(time);
println!("{}", token);

With qrcode generation

Add it to your Cargo.toml:

[dependencies.totp-rs]
version = "~0.6"
features = ["qr"]

You can then do something like:

use totp_rs::{Algorithm, TOTP};

let totp = TOTP::new(
    Algorithm::SHA1,
    6,
    1,
    30,
    "supersecret",
);
let code = totp.get_qr("user@example.com", "my-org.com")?;
println!("{}", code);

With serde support

Add it to your Cargo.toml:

[dependencies.totp-rs]
version = "~0.6"
features = ["serde_support"]

Dependencies

~0.4–1.4MB
~25K SLoC