Get online today — Domain + Hosting at discounted prices View Combo Offers ›

.htpasswd Generator

Create Apache basic-auth credentials in bcrypt, APR1 or SHA-1.

Produces the single line you need in an .htpasswd file to password-protect a directory with Apache basic authentication, along with the .htaccess block that switches the protection on.

Pick bcrypt unless you have a reason not to. The password you type is hashed on this server and never written to disk or to a log.

How it works

Basic authentication is the oldest access control on the web and still the quickest way to put a wall in front of a staging site, an admin path, or a directory of files. Apache reads a plain text file — conventionally named .htpasswd — where each line is a username, a colon, and a hash of that user's password. The browser sends the credentials on every request, Apache hashes what it receives and compares.

The algorithm you choose decides how much an attacker gains from stealing that file:

  • bcrypt ($2y$) is deliberately slow and its cost factor is tunable, so guessing is expensive no matter how much hardware is thrown at it. Apache 2.4 and later support it. This is the only option worth using on a current server.
  • APR1 ($apr1$) is Apache's salted MD5 variant. It is salted and iterated 1,000 times, which is far better than raw MD5, but trivially fast on a modern GPU. Choose it only when the server genuinely cannot do bcrypt.
  • SHA-1 ({SHA}) is unsalted and computed in nanoseconds. A stolen file is effectively a list of plaintext passwords. It exists here for appliances that accept nothing else.

Two practical cautions. First, basic auth credentials travel in a header on every request, encoded but not encrypted, so the protection is only real over HTTPS. Second, the .htpasswd file must sit outside the web root, or somewhere the server refuses to serve — leaving it next to the pages it protects is a common and serious mistake.

Note that two runs with the same password produce different bcrypt and APR1 output. That is the salt doing its job, and both lines are equally valid.

Frequently asked questions

Where should the .htpasswd file live?

Outside the document root whenever possible — one directory above public_html is the usual choice. If it must sit inside, add a rule denying access to it, and confirm by requesting the file in a browser. A downloadable .htpasswd hands an attacker every hash in it.

Which algorithm should I pick?

bcrypt, on any server running Apache 2.4 or later. Fall back to APR1 only if bcrypt is rejected, and treat SHA-1 as a compatibility shim for legacy appliances rather than a security choice.

Why is the hash different every time I generate it?

bcrypt and APR1 mix in a random salt, so the same password produces a different hash on each run. This is intentional — it stops an attacker from precomputing hashes or spotting that two accounts share a password. Any of the generated lines will authenticate correctly.

Can I use this with nginx?

Yes. nginx reads the same file format via auth_basic_user_file. It supports APR1 everywhere, and bcrypt where the platform crypt() provides it, which covers most Linux builds. The .htaccess block below is Apache-specific; nginx needs auth_basic and auth_basic_user_file in the location block instead.

Is my password sent anywhere?

It is posted to this server, hashed in memory and returned in the response. It is not written to disk, not stored in the database and not recorded in request logs. If that is still more exposure than you want, run htpasswd locally instead.

How do I add a second user?

Generate another line and append it to the same file, one user per line. To change an existing password, replace that user's line. To revoke access, delete it — the change takes effect on the next request, with no restart needed.

Related tools

Need hosting that just works?

Free SSL, daily backups and 24×7 support on every Loudhost plan.

View Hosting Plans