htpasswd generator
Create an .htpasswd line with a bcrypt hash for Apache or Nginx basic authentication. Choose the cost. The password is hashed in your browser, never sent.
Hashed in your browser. It is never sent or stored.
Each step up doubles the work for an attacker and for your server. With Basic authentication the server checks the hash on every request, so a very high cost slows every page. Apache’s own default is 5; 10 is a common balance.
user:$2y$… appears here.Only bcrypt is offered. The other htpasswd schemes (MD5-based apr1, SHA-1 and crypt) are fast to crack and should not be used for new entries.
Everything you type here stays in your browser. Nothing is sent to HardenKit or to anyone else.
How to use the htpasswd generator
- Enter the user name. It cannot contain a colon or spaces.
- Enter the password, and leave the cost at 10 unless you have a reason to change it.
- Press Generate the line and copy the result.
- Append it to your .htpasswd file, stored outside the web root, and serve the site over HTTPS.
About this tool
An .htpasswd file holds the users for HTTP basic authentication, one per line: a name, a colon and a hash of the password. Apache reads it through AuthUserFile and Nginx through auth_basic_user_file. It is the quickest way to put a login in front of a staging site, an admin path or an internal dashboard. This tool makes one line, the same as running htpasswd -nB on a server.
The hash format decides how the file fails if it leaks. The older formats, Apache’s MD5-based apr1, SHA-1 and crypt, are fast to compute, so stolen hashes are cracked quickly. bcrypt is deliberately slow and has a cost setting that doubles the work with each step. This tool writes bcrypt only, with the $2y$ prefix Apache’s own tool uses. Apache 2.4 supports it; Nginx does when the server’s crypt library does, which is common but not universal.
Two things are easy to get wrong. Basic authentication sends the password with every request, encoded but not encrypted, so it is only safe over HTTPS. And the file must sit outside the web root, or anyone can download it. bcrypt also reads only the first 72 bytes of a password, which matters only for very long passphrases; the tool warns you when that happens.
Sources
Questions
bcrypt, the -B option of Apache’s htpasswd. Apache’s documentation marks the SHA-1 and crypt formats as insecure: SHA-1 is unsalted and crypt reads only the first eight characters. The default apr1 format is an MD5 variant that is fast to compute, so it is quick to crack. This tool offers none of them.
Nginx passes the hash to the system’s crypt function, so bcrypt works where that library supports it, which is the case on most current Linux distributions and on BSD. On a system whose crypt lacks bcrypt, logins simply fail. Test one login after deploying the file.
Apache’s htpasswd defaults to 5, which is low. With basic authentication the server verifies the hash on every request, so a very high cost slows every page and asset. Ten is a common middle ground; go higher if the protected area sees little traffic.
Over HTTPS it is a sound, simple gate. Over plain HTTP it is not, because the browser sends the name and password Base64-encoded with each request and anyone on the path can read them. It also has no logout and no lockout, so use a long random password.