| Crates.io | htauth |
| lib.rs | htauth |
| version | 0.1.2 |
| created_at | 2026-01-17 16:27:19.029451+00 |
| updated_at | 2026-01-17 16:54:15.247471+00 |
| description | A library for managing htpasswd files |
| homepage | |
| repository | https://github.com/mexus/htauth |
| max_upload_size | |
| id | 2050741 |
| size | 55,145 |
A Rust library for managing htpasswd files with support for bcrypt, SHA-256, SHA-512, and APR1-MD5 password hashing algorithms.
API Documentation | Repository
use htauth::{Htpasswd, HashAlgorithm};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Open or create an htpasswd file
let mut htpasswd = Htpasswd::open(".htpasswd")?;
// Add a new user with bcrypt hashing
htpasswd.add_user("alice", "password123", HashAlgorithm::Bcrypt)?;
// Verify credentials
if htpasswd.verify_user("alice", "password123")? {
println!("Authentication successful");
}
// List all usernames
for username in htpasswd.list_users() {
println!("{}", username);
}
// Remove a user
htpasswd.delete_user("alice")?;
// Persist changes to disk
htpasswd.save()?;
Ok(())
}
| Algorithm | Identifier | Format |
|---|---|---|
| bcrypt | Bcrypt |
$2y$ / $2b$ |
| SHA-256 | Sha256 |
$5$ |
| SHA-512 | Sha512 |
$6$ |
| APR1-MD5 | Apr1 |
$apr1$ |
The library can read and verify all formats. Use detect_algorithm to determine the algorithm of an existing hash.
Htpasswd — Main type for loading, modifying, and saving password filesHashAlgorithm — Enum representing supported hash algorithmshash_password / verify_password — Standalone functions for password hashingdetect_algorithm — Detect algorithm from an existing hash stringThe library uses snafu for structured error handling. Error types are re-exported at the crate level:
HashError — password hashing errorsHtpasswdError — file parsing and I/O errorsApr1Md5Error — APR1-MD5 specific errorsFiles generated by this library are fully compatible with Apache's htpasswd tool and vice versa.
For a command-line interface, see the htauth-cli crate.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.