How to use the htpasswd generator
- Enter the username and password for the entry.
- Select the algorithm: bcrypt, SHA-1 or APR1-MD5. For bcrypt, choose the cost.
- Leave the salt empty for a random one, or enter a fixed salt to get a reproducible line.
- Click Generate and paste the
user:hashline into your.htpasswdfile.
How each algorithm works
The htpasswd generator supports three formats that Apache HTTP Server reads from a password file. Each produces a different kind of line.
bcrypt ($2y$) is the recommended choice. It uses a cost factor (you choose it here, Apache defaults to 5) and a random 128-bit salt, which makes guessing expensive. Output looks like $2y$10$salt...hash. Only the first 72 bytes of a password count.
SHA-1 ({SHA}) stores the unsalted SHA-1 digest of the password in base64. Identical passwords give identical lines and the hash is fast to attack, so SHA-1 is not suitable for passwords. It exists for compatibility.
APR1-MD5 ($apr1$) is Apache's variant of the MD5-crypt scheme: 1,000 rounds of MD5 with an 8-character salt. It was the long-time default, but MD5 is not suitable for protecting passwords today.
Format reference table
Every line in a .htpasswd file is username:hashed_password. These are real outputs for the passwords shown:
| Algorithm | Prefix | Example line |
|---|---|---|
| bcrypt | $2y$ | admin:$2y$05$abcdefghijklmnopqrstuuOQiyCxlgf/oeuTqixKmWdcYUh4Hjl0a |
| SHA-1 | {SHA} | admin:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g= |
| APR1-MD5 | $apr1$ | admin:$apr1$abcdefgh$h9FWgUz3n9YxylKLlR5SQ/ |
The bcrypt row uses the password secret with a fixed salt and cost 5, the SHA-1 row uses password, and the APR1 row uses secret with the salt abcdefgh. With a random salt, bcrypt and APR1-MD5 give a different line every run, and all of them verify.
Using the generated entry with Apache
Save the entry to a file outside your web root, such as /etc/apache2/.htpasswd, then require authentication in a virtual host or directory block:
<Directory /var/www/protected>
AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user
</Directory>
To cross-check a line, Apache's own tool prints one: htpasswd -nbB -C 10 user password for bcrypt, or openssl passwd -apr1 -salt abcdefgh password for APR1-MD5. The salt and cost in those commands let you compare the whole line.
Security considerations
Never commit .htpasswd files to version control, and treat them like any credential store. To revoke access, remove the line and reload the server.
SHA-1 and MD5 are fast general-purpose hashes and are not for passwords: a leaked file lets an attacker try billions of guesses per second. Prefer bcrypt, which Apache supports from version 2.4 and Nginx reads through the system crypt library. HTTP Basic authentication also sends the password with every request, so use it only over HTTPS.
This tool runs entirely in your browser. No network requests are made, so passwords stay on your machine. You can confirm that in the network tab of your developer tools.
Worked examples
| Example | Input | Result |
|---|---|---|
| bcrypt entry, cost 10 | Username: admin; Password: correct horse battery; Algorithm: bcrypt; bcrypt cost (4-12): 10 | Entry: admin:$2y$10$etMa4CdkyO8xMyhL/Wmjhu7v8js85fZlDoJ/OqMdNKGPCVj8k.vry; Username: admin; Hash: $2y$10$etMa4CdkyO8xMyhL/Wmjhu7v8js85fZlDoJ/OqMdNKGPCVj8k.vry; Algorithm: bcrypt ($2y$) |
| SHA-1 entry | Username: deploy; Password: hunter2; Algorithm: sha1; bcrypt cost (4-12): 10 | Entry: deploy:{SHA}87u9ZqY9S/F0eUBXjsPQEDUw4h0=; Username: deploy; Hash: {SHA}87u9ZqY9S/F0eUBXjsPQEDUw4h0=; Algorithm: SHA-1 ({SHA}) |
| APR1-MD5 with a fixed salt | Username: webmaster; Password: changeme; Algorithm: apr1; bcrypt cost (4-12): 10; Salt (optional): abcdefgh | Entry: webmaster:$apr1$abcdefgh$bAwZZ/J98zJ0QHYmK5Q/f1; Username: webmaster; Hash: $apr1$abcdefgh$bAwZZ/J98zJ0QHYmK5Q/f1; Algorithm: APR1-MD5 ($apr1$) |
FAQ
What is a .htpasswd file?
A .htpasswd file stores usernames and hashed passwords for Apache HTTP Basic Authentication. Each line contains one entry in the format username:hash.
Which algorithm should I choose?
Use bcrypt ($2y$) for new setups. It is the strongest option Apache supports. SHA-1 and APR1-MD5 exist for compatibility with old clients and software, not for protecting passwords.
Why does the bcrypt output change every time?
Bcrypt generates a new random salt for each hash. Different salts give different lines, but every one of them verifies the same password. Enter a salt to get a repeatable result.
Can I use this for Nginx?
Yes. Nginx supports the same .htpasswd file format for basic authentication when configured with the auth_basic_user_file directive.
Is my password sent to a server?
No. This htpasswd generator computes everything locally in your browser using JavaScript. Nothing is transmitted over the network.
How do I add multiple users?
Generate one entry per user and append each line to the same .htpasswd file. Do not overwrite existing lines unless you intend to replace a user.