.htpasswd generator

A username, a password, and the hashed line to put in your .htpasswd file, bcrypt by default.

Hashing
Line for the server's .htpasswd file

Send with onlyU — Your recipient gets a link they can open only once, then the link is gone. onlyU opens in a new tab with the secret already filled in: all you have to do is create the link. Free, no sign-up. How does it work?

“Copy” copies the hashed line, for the server. “Send with onlyU” passes the username and plain password to the person who will log in.

Computed in your browser. Nothing is sent unless you choose onlyU.

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 .htpasswd file; 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.

Frequently asked questions

Which algorithm should I choose for .htpasswd?

bcrypt, the default: it is deliberately slow, which holds back dictionary attacks. APR1-MD5 is only useful for a server that does not accept bcrypt.

Does Nginx accept bcrypt passwords?

Nginx relies on the system's crypt function: bcrypt works on most recent Linux distributions, but not all of them. If it fails, use APR1-MD5.

What should I send to the user?

The username and the plain-text password: that is what they will type in their browser. The hashed line only goes into the server's .htpasswd file.

Which bcrypt cost should I choose?

10 is the usual value; each step doubles the computing time. 12 strengthens protection at the price of a slightly slower check on every request.

Is .htpasswd protection enough?

It is fine for a client review area, an internal tool or a staging site, as long as it is served over HTTPS: without HTTPS, the password travels in readable form with every request.