Dead-simple password hashing with Argon2id — hash() and verify(), nothing more
cargo add philiprehberger-argon2-easyDead-simple password hashing with Argon2id — hash() and verify(), nothing more
[dependencies]
philiprehberger-argon2-easy = "0.2.0"
use philiprehberger_argon2_easy::{hash, verify};
// Hash a password
let hashed = hash("my-password")?;
// Verify a password
let is_valid = verify("my-password", &hashed)?;
assert!(is_valid);
use philiprehberger_argon2_easy::{hash_with, Profile};
// Fast hashing for interactive login
let hashed = hash_with("password", Profile::Interactive)?;
// Slow hashing for encryption keys
let hashed = hash_with("password", Profile::Sensitive)?;
use philiprehberger_argon2_easy::timing_safe_eq;
// Compare tokens or hashes safely without timing leaks
let is_equal = timing_safe_eq("token-a", "token-b");
use philiprehberger_argon2_easy::needs_rehash;
if needs_rehash(&stored_hash)? {
let new_hash = hash(password)?;
// Store new_hash
}
| Function | Description |
|---|---|
hash(password) | Hash with default OWASP-recommended parameters |
hash_with(password, profile) | Hash with a specific profile |
verify(password, hash) | Verify a password against a hash |
needs_rehash(hash) | Check if hash uses outdated parameters |
timing_safe_eq(a, b) | Constant-time string comparison |
cargo test
cargo clippy -- -D warnings
If you find this project useful: