https://github.com/messense/otpauth-rs
Two-step verification of HOTP/TOTP for Rust.
https://github.com/messense/otpauth-rs
otpauth rust
Last synced: 8 months ago
JSON representation
Two-step verification of HOTP/TOTP for Rust.
- Host: GitHub
- URL: https://github.com/messense/otpauth-rs
- Owner: messense
- License: mit
- Created: 2015-05-28T13:35:37.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2024-08-28T10:51:53.000Z (about 1 year ago)
- Last Synced: 2025-02-19T17:11:14.720Z (8 months ago)
- Topics: otpauth, rust
- Language: Rust
- Homepage: https://crates.io/crates/otpauth
- Size: 3.21 MB
- Stars: 36
- Watchers: 2
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# otpauth-rs
[](https://github.com/messense/otpauth-rs/actions/workflows/CI.yml)
[](https://crates.io/crates/otpauth)Two-step verification of HOTP/TOTP for Rust.
## Installation
Add it to your ``Cargo.toml``:
```toml
[dependencies]
otpauth = "0.5"
```## Examples
### HOTP example
```rust
use otpauth::HOTP;fn main() {
let auth = HOTP::new("python");
let code = auth.generate(4);
assert_eq!(true, auth.verify(code, 0, 100));
}
```### TOTP example
```rust
use std::time::{SystemTime, UNIX_EPOCH};use otpauth::TOTP;
fn main() {
let auth = TOTP::new("python");
let timestamp1 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
let code = auth.generate(30, timestamp1);
let timestamp2 = SystemTime::now().duration_since(UNIX_EPOCH)?.as_secs();
assert_eq!(true, auth.verify(code, 30, timestamp2));
}
```## License
This work is released under the MIT license. A copy of the license is provided in the [LICENSE](./LICENSE) file.