What it does
Produces a single .htpasswd line of the form username:hash for HTTP Basic authentication in Apache or nginx. Type a username and password, choose the hash, and copy the result. If you leave the username blank it defaults to user. Everything is computed in the page — the MD5-crypt routine and base64 SHA-1 both run client-side.
Which algorithm?
APR1 is Apache's salted MD5-crypt ($apr1$salt$hash). It applies 1000 rounds of MD5 over the password and an 8-character random salt, so the same password hashes to a different line every time — that's the salt doing its job, not a bug. It is the classic, most widely supported htpasswd format and nginx understands it too. SHA-1 ({SHA}base64) is a single, unsalted SHA-1 — compact and simple, but with no salt and no work factor two identical passwords always produce the same hash, so it's the weakest option here.
For a new setup prefer bcrypt ($2y$…) where your server supports it — Apache's htpasswd -B or nginx with a bcrypt-aware build — because it has a tunable cost factor and resists brute-forcing far better than MD5 or SHA-1. This tool doesn't generate bcrypt; use it when APR1/SHA-1 compatibility is what you specifically need.
How to use
- Create the file, e.g.
/etc/apache2/.htpasswd, with one user per line. Paste each generated line in. - Apache: point a
<Directory>or.htaccessblock at it withAuthType Basic,AuthUserFile, andRequire valid-user. See the .htaccess helper. - nginx:
auth_basic "Restricted";andauth_basic_user_file /path/.htpasswd;inside thelocationorserverblock.
Gotchas
- Basic auth sends credentials base64-encoded, not encrypted — always serve the protected area over HTTPS or the password travels in the clear.
- Because APR1 re-salts each time, don't be alarmed that re-generating gives a different line; any correct line will still authenticate the password.
- MD5-crypt and especially unsalted SHA-1 are fast to brute-force. Use a long, random password (generate one with the Password generator) rather than a memorable word.
Privacy
Hashing runs locally; the username and password are never uploaded.