When you generate a .htpasswd entry, you have to choose an algorithm. The htpasswd tool supports four: bcrypt, APR1, SHA, and crypt. They are not equally secure. In fact, three of them should not be used for new passwords in 2026. Let's look at each one and explain why bcrypt is the only one you should choose.
The Four Formats
Each algorithm produces a different hash format. Here is what they look like:
Bcrypt ($2y$):
admin:$2y$05$X9qo8uLOickgx2ZMRZoMyeIjZAgcfl7p92ldGxad68LJ
The $2y$ prefix identifies it as bcrypt. The 05 is the cost factor. The next 22 characters are the salt, and the rest is the hash.
APR1 ($apr1$):
admin:$apr1$R7Tb.m3.$abc123def456ghi789jkl012mno345pqr678
The $apr1$ prefix identifies it as APR1. The string between the second and third dollar signs is the salt. The rest is the hash.
SHA ({SHA}):
admin:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=
The {SHA} prefix identifies it as SHA-1. The rest is the base64-encoded hash.
Crypt (no prefix):
admin:1X.2b3.4a5b6c7d8e9f0g
No prefix and a short hash. This is the original Unix crypt algorithm based on DES. It is from the 1970s and should never be used.
Bcrypt: The Recommended Choice
Bcrypt is the algorithm you should use for new .htpasswd entries. It is the same bcrypt we cover in our bcrypt explained post: a deliberately slow, adaptive password hashing function based on the Blowfish cipher.
Here is why bcrypt is the right choice for .htpasswd:
**It is slow.** Bcrypt with a cost factor of 5 (the htpasswd default) takes about 100 milliseconds per hash. An attacker who steals your .htpasswd file and tries to crack it with a GPU will get maybe a few hundred guesses per second per GPU. Compare that to APR1, where the same GPU can try millions per second.
**It is adaptive.** If hardware gets faster and cost 5 becomes too easy to crack, you can bump the cost factor to 10 or 12 and re-hash. The cost factor is embedded in the hash, so Apache knows which cost to use for verification.
**It is widely supported.** Apache 2.4 and later support bcrypt in .htpasswd files out of the box. Most modern Apache installations default to bcrypt when you use the -B flag.
**It uses a unique salt per password.** Even if two users have the same password, their hashes will be completely different. This prevents rainbow table attacks and makes batch cracking slower.
To generate a bcrypt .htpasswd entry with the command-line tool:
bash htpasswd -cB /path/to/.htpasswd admin
The -B flag forces bcrypt. You can also set the cost factor with -C (default is 5):
bash htpasswd -cBC 10 /path/to/.htpasswd admin
Or you can generate one in your browser with our htpasswd generator, which supports bcrypt and lets you adjust the cost factor.
APR1: The Legacy Default
APR1 is Apache's custom MD5-based password hashing algorithm. It was introduced in the 1990s as an improvement over the original Unix crypt, which was limited to 8-character passwords and used DES.
APR1 applies MD5 1,000 times with a salt. When it was introduced, this was considered adequate. MD5 was still considered secure, and 1,000 iterations was enough to slow down attacks on the hardware of the day.
Today, APR1 is weak. MD5 is broken (collisions can be found in seconds), and 1,000 iterations is trivially fast for a modern GPU. A single GPU can compute millions of APR1 hashes per second. If an attacker steals your .htpasswd file with APR1 hashes, they can try the top 10,000 most common passwords against every user in minutes.
APR1 is still the default on some older Apache installations and some versions of the htpasswd tool. If your .htpasswd file contains APR1 hashes, you should plan a migration to bcrypt. You do not need to do it all at once: add new users with bcrypt, and when existing users need a password reset, give them a bcrypt hash.
SHA: Even Worse
The SHA option (htpasswd -s) uses SHA-1. It is a single-pass hash with no salt and no iterations. This means:
- No salt means the same password always produces the same hash. An attacker can precompute a table of common passwords and look them up instantly. - No iterations means it is as fast to compute as possible. A GPU can compute billions of SHA-1 hashes per second. - SHA-1 itself is broken for collision resistance, though this does not directly affect password hashing.
SHA-1 for password hashing is worse than APR1. It is worse than plain crypt in some ways because at least crypt has a salt. There is no reason to use SHA for .htpasswd entries in 2026. If your existing file has SHA entries, replace them.
Crypt: Do Not Use
The original Unix crypt algorithm is based on DES and dates from the 1970s. It has a 13-character hash, supports only 8-character passwords, and uses a 2-character salt. It is trivially crackable on any modern hardware. If your .htpasswd file has crypt entries, they might as well be plaintext.
Some very old Apache installations or very old Unix systems may default to crypt. If you encounter it, migrate immediately.
Compatibility Notes
One thing to be aware of: not all algorithms are supported on all systems.
**Bcrypt** requires Apache 2.4 or later. If you are running Apache 2.2, bcrypt hashes will not work. Check your Apache version before generating bcrypt entries. If you are on Apache 2.2, your best option is APR1 (or upgrade Apache).
**APR1** is supported by virtually every Apache version and every nginx version. It is the most compatible option, which is why it is still the default on some systems despite being weaker.
**SHA** is supported by Apache 2.2 and later. It is widely compatible but, as we discussed, should not be used.
**Crypt** is supported everywhere but should not be used anywhere.
For nginx, the same .htpasswd file format works. nginx supports bcrypt, APR1, and crypt. It does not support the SHA format. If you are using nginx, use bcrypt or APR1. See our nginx basic auth guide for setup details.
Which One Should You Choose?
The answer is simple: use bcrypt. It is the most secure option, it is supported by modern Apache and nginx, and it is what the htpasswd tool defaults to on current systems. Use a cost factor of at least 5 (the default), and consider 10 or higher for high-security applications.
If you are stuck on an old Apache version that does not support bcrypt, use APR1 as a fallback. It is not great, but it is better than SHA or crypt. And plan an upgrade.
If you have an existing .htpasswd file with mixed algorithms, do not panic. Apache handles each entry independently based on its prefix. Add new users with bcrypt, and migrate old users when you can.
You can generate bcrypt .htpasswd entries right now with our htpasswd generator. And for help setting up the full .htaccess protection, read our Apache .htaccess guide.