https://github.com/fosskers/totp-lite
A simple, correct TOTP library.
https://github.com/fosskers/totp-lite
authentication totp
Last synced: 10 months ago
JSON representation
A simple, correct TOTP library.
- Host: GitHub
- URL: https://github.com/fosskers/totp-lite
- Owner: fosskers
- License: mit
- Created: 2020-08-20T22:35:13.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2025-08-12T00:50:51.000Z (10 months ago)
- Last Synced: 2025-08-12T02:37:33.247Z (10 months ago)
- Topics: authentication, totp
- Language: Rust
- Homepage:
- Size: 49.8 KB
- Stars: 31
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://github.com/fosskers/totp-lite/actions?query=workflow%3A%22Rust%22)
[](https://crates.io/crates/totp-lite)
# 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:
```rust
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::(password, seconds);
assert_eq!(8, result.len());
```
For full control over how the algorithm is configured, consider
`totp_custom`.
## Resources
- [RFC6238: TOTP][RFC6238]
- [RFC6238 Errata](https://www.rfc-editor.org/errata_search.php?rfc=6238)
[RFC6238]: https://tools.ietf.org/html/rfc6238
License: MIT