htauth
A Rust library for managing htpasswd files with support for bcrypt, SHA-256, SHA-512, and APR1-MD5 password hashing algorithms.
API Documentation | Repository
Usage
use ;
Supported Hash Algorithms
| 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.
API Overview
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 string
Error Handling
The 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 errors
Apache Compatibility
Files generated by this library are fully compatible with Apache's htpasswd tool and vice versa.
CLI
For a command-line interface, see the htauth-cli crate.
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.