Expand description
A lightweight alternative to Apache’s htpasswd tool.
This library provides functionality to create, read, and modify htpasswd files with support for bcrypt, SHA-256, SHA-512, and APR1-MD5 password hashing algorithms.
§Example
use htauth::{Htpasswd, HashAlgorithm};
// Create or open an htpasswd file
let mut htpasswd = Htpasswd::open(".htpasswd")?;
// Add a new user
htpasswd.add_user("alice", "password123", HashAlgorithm::Bcrypt)?;
// Verify a user's password
if htpasswd.verify_user("alice", "password123")? {
println!("Password correct!");
}
// List all users
for user in htpasswd.list_users() {
println!("{}", user);
}
// Save changes
htpasswd.save()?;Structs§
- Htpasswd
- Represents an htpasswd file with user credentials.
Enums§
- Apr1
Md5Error - Errors that can occur during APR1-MD5 operations.
- Hash
Algorithm - Supported password hashing algorithms.
- Hash
Error - Errors that can occur during password hashing and verification.
- Htpasswd
Error - Errors that can occur during htpasswd file operations.
Functions§
- detect_
algorithm - Detect the hash algorithm from a hash string.
- hash_
password - Hash a password using the specified algorithm.
- verify_
password - Verify a password against a hash.