htpasswd Generator
Create .htpasswd lines with bcrypt (or APR1) for nginx and Apache basic authentication, check a password against a line, and copy the server config. Runs in your browser.
● Runs 100% in your browser — nothing you type leaves this page.
Need a strong one? Password Generator
Fill in a user name and a password, then Generate.location /admin/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htpasswd;
}<Location "/admin">
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Location>sudo htpasswd -B -C 10 -c /etc/nginx/.htpasswd anna # -c creates (or empties!) the file sudo htpasswd -B -C 10 /etc/nginx/.htpasswd another-user # add a user sudo chown root:www-data /etc/nginx/.htpasswd && sudo chmod 640 /etc/nginx/.htpasswd
Check a password against a line
How to use it
- Type a user name and a password. For a strong password, use the Password Generator.
- Keep bcrypt (the default) and click Generate. You get a
user:hashline for your.htpasswdfile. - For several users, click Add to file after each one, then copy the whole file.
- Copy the nginx or Apache block under it, and point it at the file.
The password is hashed in your browser and never sent anywhere, nor kept in the page address.
bcrypt or APR1?
- bcrypt (
$2y$…) is slow on purpose: if the file leaks, each guess costs time. It’s whathtpasswd -Bwrites. The cost sets how slow: 10 is a good default; each step up doubles the time, on your server too, at every request that logs in. - APR1-MD5 (
$apr1$…) is whathtpasswd -mwrites, and what very old servers understand. It’s fast to brute-force, so use it only when bcrypt doesn’t work.
Plain text, {SHA} and DES crypt() lines aren’t offered: they’re too weak to recommend.
nginx and bcrypt
nginx checks the hash with the system’s crypt() function, so bcrypt works when the system’s C library supports it. The checks this site runs (see below) confirm it on the official nginx image and on nginx:alpine. If an older system answers every correct login with 401, check the error log, and switch to APR1 there.
Where to put the file
sudo chown root:www-data /etc/nginx/.htpasswd # "apache" on RHEL-based systemssudo chmod 640 /etc/nginx/.htpasswdsudo nginx -t && sudo systemctl reload nginxKeep it outside the web root, so it can never be downloaded. Basic authentication sends the password with every request, so use it only over HTTPS.
FAQ
Can I check a password against an existing file?
Yes: paste one line of the file and the password under Check a password against a line. It works for bcrypt and APR1 lines.
The browser keeps asking for the password
The line doesn’t match: a typo, a user name with a different case, a file the server can’t read, or a different file than the one in the config. sudo nginx -T | grep auth_basic_user_file shows which file nginx uses. The nginx cheat sheet has the full block.
nginx answers without asking for a password
Look for a return in that location (or a rewrite … last to a place without auth_basic). return runs before nginx checks the password, so return 200 … answers everyone. Protect the location that serves the content, or the proxy_pass to your app, not a location that only returns.
Why is the line different every time?
Each hash gets a new random salt, so the same password never gives the same line. Every one of them is valid.
How is this checked?
Lines made by this tool are checked with Apache’s own htpasswd -v, and real nginx servers are asked to log in with them, on the official image and on Alpine; lines made by htpasswd are checked by the tool’s own verifier.