FormatterHQ

Htpasswd Generator

Turn username:password pairs into .htpasswd entries for Apache or Nginx basic authentication. bcrypt by default, with APR1-MD5 and SHA-1 for older servers.

Input TEXT
Output TEXT
Ready.

How to use the Htpasswd Generator

  1. Enter one username:password pair per line; lines starting with # are skipped.
  2. Choose the Hash: bcrypt (recommended), Apache MD5 (apr1) or SHA-1 {SHA} (legacy).
  3. For bcrypt, set the bcrypt cost between 4 and 15 (10 is the default).
  4. Click Generate .htpasswd and paste the lines into your .htpasswd file on the server.

Htpasswd generator for Apache and Nginx

This htpasswd generator converts plain username:password pairs into the hashed lines that Apache's mod_auth_basic and Nginx's auth_basic_user_file expect. It does the same job as the htpasswd command-line utility, which is handy when you are on a machine without apache2-utils installed or need entries for several users at once.

What is an .htpasswd file?

An .htpasswd file is a plain text list with one user per line: the username, a colon, and a password hash. The web server reads it when a protected location is requested, hashes the password the visitor typed, and compares. The file never needs to contain the real password, only a hash in a format the server recognizes.

Example

With the tool's sample input and the default bcrypt option at cost 10, you get one line per user:

admin:$2y$10$prK.TZ9TxuKtfHcAnM5R9uhdBgNTMMIMMfBP7HLt6Gk3A0vLALJzS
alice:$2y$10$rY.0TmwbvWR4VI4qCTSqrujyjUhMynYUNlCT48u0fAeSSzf08hKGm

Because every hash gets a fresh random salt, running the tool again produces different output for the same password. Both versions verify correctly. The same password with the other two algorithms looks like this:

admin:$apr1$dOwYH/tZ$6Ctd2kG2teqmAbLWJWBWo.
admin:{SHA}iEYguQJFGKubtHRfunjGIVgU2P0=

Hash options explained

OptionPrefixNotes
bcrypt (recommended)$2y$Slow, salted, tunable cost. Supported by Apache 2.4+ and by Nginx on systems whose crypt() library understands bcrypt, such as distributions built on libxcrypt.
Apache MD5 (apr1)$apr1$Salted MD5 with 1,000 rounds. Works on every Apache and Nginx version, but it is fast to brute force by current standards.
SHA-1 {SHA} (legacy){SHA}Unsalted SHA-1 in Base64. Identical passwords give identical hashes. Only use it for old systems that accept nothing else.

The bcrypt cost is a base-2 logarithm: each step doubles the work. Cost 10 is a reasonable default for basic auth because the server hashes the password on every request. Going to 12 or higher makes each protected page load noticeably slower.

Using the output

For Apache, point AuthUserFile at the file inside a <Directory> block or .htaccess, with AuthType Basic and Require valid-user. For Nginx, add auth_basic "Restricted"; and auth_basic_user_file /etc/nginx/.htpasswd; to the server or location block. Keep the file outside the web root and readable only by the server user.

Basic authentication sends the credentials Base64-encoded with every request, so always serve protected areas over HTTPS. You can see exactly what the browser sends with the Basic Auth header generator.

Common errors and fixes

  • Nginx always returns 401 with bcrypt – Nginx relies on the operating system's crypt() function, and some older distributions ship one without bcrypt. Use apr1 on those systems.
  • "must look like username:password" – each line needs a colon. Passwords may contain colons, because only the first colon splits the line, but usernames cannot contain spaces or colons.
  • Long passwords – bcrypt only uses the first 72 bytes of a password. A longer passphrase still works, but characters beyond that limit do not add strength.
  • Windows line endings – if you edit the file on Windows, save it with LF endings; a trailing carriage return can break the last field.

Need a strong password first? Create one with the password generator, or hash a single value with the dedicated bcrypt generator.

Privacy

All hashing happens in your browser, and salts come from crypto.getRandomValues. The usernames and passwords you type are never uploaded.

Frequently asked questions

Which htpasswd format does Nginx support?
Nginx accepts APR1 ($apr1$), {SHA} and any scheme the operating system crypt() function supports, which includes bcrypt on most current distributions. If bcrypt entries are rejected on an older server, switch to APR1.
Why is the hash different every time I generate it?
bcrypt and APR1 add a random salt to each hash, so the same password produces a new string each run. The salt is stored inside the hash, which is how the server can still verify the password. Only the legacy {SHA} format is deterministic.
Can I generate entries for several users at once?
Yes. Put one username:password pair on each line and the tool returns one .htpasswd line per user in the same order. Blank lines and lines starting with # are ignored.
What bcrypt cost should I pick for basic auth?
Cost 10 is a sensible balance for most servers. Basic auth re-checks the password on every request, so a very high cost adds latency to each page and asset load. Raise it only if your traffic is light.
Is the $2y$ prefix the same as $2a$ or $2b$?
They are variants of bcrypt that differ only in how old implementations handled edge cases. Apache writes $2y$, and this tool does the same for compatibility with the htpasswd utility.

Last updated September 26, 2026

Related tools

Keccak Hash Generator Generate original Keccak-224/256/384/512 hashes, including the Keccak-256 used by Ethereum and Solidity. MD2 Hash Generator Generate the MD2 hash of any text or file online. Instant 128-bit digest in hex, computed in your browser. MD4 Hash Generator Generate the MD4 hash of any text or file online. Instant 128-bit digest in hex, computed in your browser. MD5 Hash Generator Generate the MD5 hash of any text or file online. Instant 128-bit digest in hex, computed in your browser. NTLM Hash Generator Generate the Windows NTLM (NT) password hash — MD4 of the UTF-16LE password — online. Password Strength Checker Estimate password entropy and crack time for online and offline attacks, and spot common patterns — checked privately in your browser. PBKDF2 Hash Generator Generate PBKDF2-HMAC-SHA256/512 derived keys and Django-style password hashes with your own salt and iteration count, using WebCrypto. RIPEMD-160 Hash Generator Generate the RIPEMD-160 hash of any text or file online. Instant 160-bit digest in hex, computed in your browser. RSA Key Pair Generator Generate RSA 2048, 3072 or 4096-bit public/private key pairs in PEM (PKCS#8, PKCS#1) or JWK format with WebCrypto, entirely offline. Scrypt Hash Generator Derive scrypt password hashes and keys with custom N, r, p and salt; output as hex, Base64 and common encoded formats. Self-Signed Certificate Generator Create a self-signed SSL/TLS certificate and RSA key for localhost, dev servers or internal tools. Generated locally with WebCrypto. SHA-1 Hash Generator Generate the SHA-1 hash of any text or file online. Instant 160-bit digest in hex, computed in your browser.