An .htpasswd line, ready to paste
The .htpasswd file lists the accounts allowed into an area protected by Apache or Nginx, one
account per line: the username, a colon, then the hashed password. The generator builds this
line from a username and a password, typed or generated. The hash is computed in your browser, and the page is
not allowed to make network requests.
alice:$2y$10$…
The result is equivalent to htpasswd -nbB -C 10 alice password, without installing Apache's tools
and without leaving the password in your terminal history.
Choosing the algorithm
- bcrypt, the default:
$2y$prefix, cost adjustable from 10 to 12. bcrypt is deliberately slow, which holds back dictionary attacks if the file ever leaks. Each step of cost doubles the computing time, for the attacker as well as for the server, which checks the password on every request. bcrypt only takes the first 72 bytes of the password into account. - APR1-MD5:
$apr1$prefix, an Apache-specific variant of MD5. It is weak against today's hardware: keep it for servers that do not accept bcrypt.
The SHA-1 format ({SHA}), which hashes without a salt, is not offered.
Apache or Nginx
Apache has verified bcrypt passwords itself since version 2.4.4. Nginx, on the other hand, hands bcrypt over to
the system's crypt function: depending on the distribution's C library, it may or may not
recognize it. Give it a try; if it fails, APR1-MD5, which Nginx verifies on its own, works everywhere. The
configuration takes just a few lines:
# Apache (.htaccess or site configuration)
AuthType Basic
AuthName "Restricted area"
AuthUserFile /path/to/.htpasswd
Require valid-user
# Nginx (server or location block)
auth_basic "Restricted area";
auth_basic_user_file /etc/nginx/.htpasswd;
Keep the .htpasswd file outside the published directory, readable by the web server only, and
serve the protected area over HTTPS: the browser sends the username and password again with every request.
What goes on the server, what goes to the user
The two halves of the result have different destinations:
- the hashed line goes into the server's
.htpasswdfile; it cannot be used to log in; - the username and plain-text password go to the person who needs to get in: that is what they will type when their browser asks for them.
For client acceptance testing, a staging site or an internal tool, these credentials often have to go to someone outside your team. “Send with onlyU” passes them on: onlyU encrypts them in your browser and creates a link that opens only once, valid for 24 hours, then disappears. The credentials do not linger in a ticket or an email. For the complete setup, read our guide on how to password protect a directory.