Available on crate feature
crypto only.Expand description
Password hashing and secure token generation.
Enabled by the crypto Cargo feature:
rust-web-server = { version = "17", features = ["crypto"] }§Password hashing
Uses Argon2id (OWASP recommended) with a random 128-bit salt. The output is a self-describing PHC string that includes the algorithm, parameters, salt, and hash — store it as-is in your database.
use rust_web_server::crypto::{hash_password, verify_password};
let hash = hash_password("hunter2").unwrap();
assert!(verify_password("hunter2", &hash).unwrap());
assert!(!verify_password("wrong", &hash).unwrap());§Secure token generation
use rust_web_server::crypto::generate_token;
let token = generate_token(32); // 32 random bytes → 64-char lowercase hex stringStructs§
- Crypto
Error - Error returned by crypto operations.
Functions§
- generate_
token - Generate
n_bytesof cryptographically secure random bytes and return them as a lowercase hex string of lengthn_bytes * 2. - hash_
password - Hash
passwordusing Argon2id with a random salt. - verify_
password - Verify
passwordagainst a PHC hash string produced byhash_password.