HTPasswd Generator
Generate Apache .htpasswd entries using bcrypt, APR1, SHA-1, or crypt. Paste straight into your password file.
$2y$Recommended. Supported by Apache 2.4+ and Nginx with the auth_basic module. Cost rounds adjustable below.
OWASP recommends cost ≥ 10. Higher = slower for attackers AND legitimate logins. Cost 14 takes ~1 second per hash on a modern server.
Written by Ishan Karunaratne · Last reviewed:
Algorithm Comparison
| Algorithm | Prefix | Salted | Speed (1 GPU) | Verdict |
|---|---|---|---|---|
| bcrypt | $2y$ | Yes | ~30K/sec | Recommended |
| APR1 | $apr1$ | Yes | ~50M/sec | Legacy only |
| SHA-1 | {SHA} | No | ~25B/sec | Don't use |
| DES crypt | (13 chars) | 2-byte | ~700M/sec | Broken |
Speeds are approximate single-GPU hashcat benchmarks (RTX 4090). Lower is better for password security.
Apache Configuration Example
After saving the generated line to /etc/apache2/.htpasswd, configure Apache to require authentication. In your virtual host or a .htaccess file:
<Location "/admin">
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>Reload Apache with apachectl graceful (or systemctl reload apache2). Place the .htpasswd file outside your document root — never inside a directory the web server might serve as a static file.
Nginx Configuration Example
Nginx uses the same .htpasswd format. In your server or location block:
location /admin {
auth_basic "Restricted Area";
auth_basic_user_file /etc/nginx/.htpasswd;
}Reload Nginx with nginx -s reload. Run nginx -t first to validate the config.
Common Pitfalls
- •.htpasswd inside the document root. Apache and Nginx do not block access to files starting with a dot by default. If you put .htpasswd inside
/var/www/html/, attackers may download it directly. Store it in/etc/or another directory the web server doesn't serve. - •Forgetting the newline. Every entry needs to end with a newline. If you paste the line without one, the next append may concatenate onto your last user.
- •Using APR1 in 2026. Many tutorials still default to APR1 because that's what plain
htpasswd(without flags) emits. Usehtpasswd -Bfor bcrypt, or just use this tool. - •Wrong file permissions. The .htpasswd file must be readable by the web server user (www-data, apache, nginx). 644 is fine if the file owner is the same user; 640 if owned by root with the web server in the group.
- •Basic Auth over plain HTTP. HTTP Basic Authentication sends credentials base64-encoded in every request — anyone on the network can decode them in real time. Always terminate Basic Auth behind HTTPS.