htpasswd Generator: bcrypt, apr1, SHA-1 and crypt

Turn a username and password into one user:hash line for an Apache .htpasswd file. Every format - plain, crypt, apr1, SHA-1 and bcrypt - is computed in your browser and verified against openssl passwd, Apache htpasswd and glibc crypt, so the password never leaves the tab.

Runs locally in your browser

How to create an htpasswd entry for Apache basic authentication

Type a username and a password, choose a format and press Generate htpasswd entry. The page returns one user:hash line, ready to append to a .htpasswd file, and lists the caveats that apply to the format you picked before you paste it anywhere.

Every hash is computed in your browser. The apr1 entry matches openssl passwd -apr1 and htpasswd -m, the bcrypt entry matches the $2y$ lines Apache writes with htpasswd -B, and the SHA-1 entry is the {SHA} form of htpasswd -s. The password is never uploaded, and no request leaves the tab while you type.

  1. Enter the username exactly as it will be typed at the login prompt. Apache limits usernames to 255 bytes and rejects the colon, because the colon separates the two halves of the line.
  2. Enter the password. On Windows htpasswd truncates passwords to 255 characters, and bcrypt ignores everything after the first 72 bytes; the page warns you when a limit applies.
  3. Pick the format. bcrypt is the recommended choice today, MD5 (apr1) is what htpasswd writes by default, and crypt, SHA-1 and plaintext remain for legacy servers and existing files.
  4. For bcrypt, set the cost factor. Apache starts at 5 and accepts 4-17; this page starts at 10 and allows 4-14, because the key schedule runs in your browser and doubles with every step.
  5. Press Generate htpasswd entry, read the notes above the result and use Copy to take the line. Check it on the server with htpasswd -vb /etc/apache2/.htpasswd alice before you rely on it.

What each htpasswd format writes, and which one to choose

What each format writes

plain stores the password as typed, and httpd accepts that only on Windows and Netware. crypt is the old Unix routine: 13 characters, a 2-character salt, and only the first 8 characters of the password - everything after that is silently discarded, which is why a long passphrase loses its strength here.

MD5 (apr1) writes $apr1$salt$hash: an Apache-specific scheme that runs 1000 MD5 rounds over the password and an 8-character salt, and it is what htpasswd -m produces. SHA-1 writes {SHA} followed by the base64 of a SHA-1 digest; unlike the others it has no salt, so one password always yields the same line. bcrypt writes $2y$cost$salt$hash, salts every entry with 16 random bytes and repeats the key schedule 2^cost times.

Where the entry goes

A .htpasswd file holds one user:hash line per account and is read by Apache through AuthUserFile. A minimal protected directory uses AuthType Basic, AuthName "Restricted", AuthUserFile /etc/apache2/.htpasswd and Require valid-user. Keep the file outside the document root and readable by the web server user only.

From a shell the same lines come from htpasswd: -B adds bcrypt (-C sets the cost), -m the apr1 form, -s SHA-1 and -d crypt. One file may mix formats, so an old crypt row and a new bcrypt row can coexist; verify any line with htpasswd -vb file user.

Security notes

HTTP basic authentication sends the password base64-encoded with every request, so the connection has to be HTTPS: the hash protects the file, not the wire. crypt, SHA-1 and apr1 are fast to compute, which is what an attacker who steals the file wants, so use bcrypt for new entries and replace the old rows as accounts are touched.

The generator neither stores nor transmits the password: hashing runs in the page and the salt comes from the browser's random number generator. Cost 10 takes roughly a fifth of a second here and cost 12 about a second, so the field stops at 14 even though htpasswd accepts up to 17.

Recent tools: