htpasswd Generator

Enter your own username and password, choose an Apache Basic Auth hash format, and copy a ready-to-paste .htpasswd line. APR1/MD5 and SHA-1 are generated in your browser; bcrypt gives you the safer server-side htpasswd -B command.

Private by design: your username and password are processed locally in this page. Nothing is sent to StashGrid.

Generated .htpasswd line

Enter a username and password, then generate.

Which hash should I use?

bcrypt: recommended for new Apache installsAPR1/MD5: widely compatibleSHA-1: legacy onlyPlain text: Windows/NetWare only

Apache documents bcrypt as currently very secure. APR1/MD5 is Apache-specific and commonly compatible, but older. This page now validates APR1 against Apache/OpenSSL example vectors. SHA-1, crypt, and plaintext are legacy formats and should only be used when your host requires them.

A practical guide to .htpasswd and Apache Basic Auth

HTTP Basic Authentication is the oldest access control on the web and still one of the most useful. It takes about two minutes to set up, needs no database and no application code, and is the right tool for putting a staging site behind a door, keeping crawlers off an internal dashboard, or protecting an admin endpoint that only a handful of people should reach.

It is also widely misconfigured, usually in ways that are invisible until someone goes looking. The sections below cover the decisions that actually matter.

What Basic Auth does, and what it does not

When a browser hits a protected resource, Apache returns 401 with a WWW-Authenticate header. The browser prompts, then sends the username and password on every subsequent request in an Authorization header, encoded as base64.

Base64 is an encoding, not encryption. Anyone who can see the traffic can decode the credentials instantly. Over plain HTTP, Basic Auth is equivalent to sending the password in the clear. HTTPS is not a recommendation here, it is a requirement — and it should be enforced with a redirect so the credentials are never sent over an unencrypted connection even once.

Choosing a hash format

The .htpasswd file stores one username:hash pair per line. Apache supports four formats, and they are not equivalent:

The bcrypt cost factor, and an honest caveat

Apache's htpasswd -B defaults to a cost of 5, which is low — it dates from when the feature was added and has not moved since. For a password file, -C 10 or -C 12 is a more appropriate setting, and each step up doubles the work required to test a candidate password.

There is a real trade-off, though, and it is specific to Basic Auth. Basic Auth has no session: the browser resends the credentials on every single request, and Apache verifies the hash every time. At cost 12, that verification takes on the order of a quarter of a second, and a page pulling forty assets pays it forty times. For a staging site with three users this is irrelevant. For anything with real traffic, cost 10 is a sensible ceiling, and the honest answer is that a site needing both strong hashing and throughput should not be using Basic Auth as its primary authentication.

Where to put the file

This is the mistake that undoes everything else. The .htpasswd file must live outside your document root. If it sits next to index.html, it may be downloadable over the web, and an attacker with the file can crack it offline at their leisure with nothing to rate-limit them.

Put it somewhere like /etc/apache2/.htpasswd or a private directory a level above public_html, and give it restrictive permissions — readable by the Apache user, nobody else. If your hosting forces it inside the web root, add an explicit rule denying access to files matching .ht* and verify by requesting the file in a browser. Most distributions ship that rule by default; do not assume yours has it.

Wiring it up

The .htaccess block in the tool above is the standard Apache 2.4 form. Two details are worth knowing:

For .htaccess to be read at all, the surrounding directory must be covered by AllowOverride AuthConfig or AllowOverride All in the main server configuration. If you control the server config, putting the directives there instead of in .htaccess is faster — Apache re-reads .htaccess on every request.

What Basic Auth cannot do

Knowing the gaps is what keeps it in its lane:

When to reach for something else

If you need sessions, roles, password resets, or an audit trail, Basic Auth is the wrong layer and the answer is authentication in your application. If you want SSO in front of a site you would rather not modify, an identity-aware proxy — Cloudflare Access, an OIDC module such as mod_auth_openidc, or your cloud provider's equivalent — gives you real accounts and logging without touching the application. Digest authentication is not the upgrade it appears to be; it is effectively deprecated and carries its own storage problems.

For its actual purpose — a quick, dependency-free gate on something that should not be publicly readable — Basic Auth over HTTPS with a bcrypt password file remains a perfectly reasonable answer.

Related password tools

FAQ

Can I enter my own password?

Yes. Type your own password, or use Generate Password to create a random one.

Where should the .htpasswd file go?

Outside your document root — somewhere like /etc/apache2/.htpasswd or a directory above public_html. If it sits inside the web root it may be downloadable, and anyone who fetches it can crack the hashes offline with nothing to stop them. If your host forces it inside the web root, add a rule denying access to .ht* files and confirm by requesting the file in a browser.

Why does bcrypt show a command instead of a browser hash?

bcrypt is the best choice for new Apache deployments, but the safest no-dependency workflow is to generate the password locally and run Apache's own htpasswd command on your server.

What bcrypt cost should I use?

Apache's htpasswd -B defaults to cost 5, which is low. Use -C 10, or 12 if the site is quiet. Bear in mind that Basic Auth has no session — the browser resends credentials on every request and Apache rehashes every time — so a high cost multiplies across every asset on a page. Cost 10 is a sensible ceiling for anything with real traffic.

Is APR1 the same as normal MD5?

No. APR1 is Apache's MD5-based htpasswd format. It starts with $apr1$, is salted and iterated 1,000 times, and is not the same as a plain MD5 checksum. It is weak by modern standards but supported almost everywhere.

Why is unsalted SHA-1 a problem here?

Because it is unsalted, the same password always produces the same hash, so precomputed lookup tables crack it immediately and identical passwords are visible as identical lines in the file. Use it only when a host supports nothing better.

Is Basic Auth safe over plain HTTP?

No. Credentials are base64-encoded, which is an encoding and not encryption — anyone who can see the traffic can decode them instantly. Serve the protected area over HTTPS and redirect HTTP to it, so credentials are never sent unencrypted even once.

Why am I getting a 500 error after adding the directives?

Most often AuthUserFile has a relative path. It must be an absolute filesystem path, not a URL and not a path relative to the web root. The other common causes are AllowOverride not permitting AuthConfig in that directory, or a 2.2-era Order/Allow/Deny snippet pasted into an Apache 2.4 server, which wants Require instead.

How do I log out of Basic Auth?

There is no clean way. The browser caches the credentials for the session and no cross-browser mechanism reliably clears them. Users close the browser or use a private window. If you need real logout, you need authentication in your application rather than at the web server.

Does Basic Auth lock out repeated failed attempts?

No. Apache will check attempts as fast as they arrive. If the endpoint is reachable from the internet, pair it with fail2ban or similar, watching the Apache error log for repeated 401s.

Can several people share one line in the file?

They can, and in practice they do, which is the problem — the credential gets passed around and never changes. Give each person their own username and line so you can remove one without disrupting everyone else.

Is my password sent to StashGrid?

No. The username, password, and APR1 or SHA-1 hashing all run in your browser. Nothing is transmitted or stored. bcrypt intentionally produces a command for you to run on your own server instead.