induwara.lk
induwara.lkDeveloper · Utility

.htpasswd Generator — Apache & Nginx Basic Auth

Create a username:hash line for HTTP Basic Auth in your browser. Choose bcrypt, APR1-MD5, or SHA-1, get a copy-ready .htaccess snippet, and verify a password against an existing hash. Your password is hashed locally and never uploaded.

By Induwara AshinsanaUpdated Jun 24, 2026
.htpasswd Generator
Hash algorithm
Recommended — strong, salted, tunable cost.
10 · 1,024 rounds

Higher cost = slower to compute and slower to brute-force. 10–12 is a sensible range for 2026 hardware.

Formats follow the Apache htpasswd program (bcrypt -B, APR1 -m, SHA-1 -s) and are read by Apache mod_authn_file and Nginx auth_basic. Sources cited below.

How it works

HTTP Basic Authentication (defined in RFC 7617) protects a directory by asking the browser for a username and password. Apache and Nginx check those credentials against a flat file — conventionally named .htpasswd — where every line is username:hash. The server never stores the plaintext password: it hashes whatever the user types and compares the result to the stored hash. This tool builds those lines, using the exact formats Apache's htpasswd program writes.

Three hashing schemes are supported, matching the htpasswd CLI flags:

  • bcrypt (htpasswd -B) — generates a 16-byte random salt and runs the Blowfish-based bcrypt key-derivation function for 2cost rounds, emitting $2y$<cost>$<22-char salt><31-char hash>. The cost factor (4–15) is a deliberate slowdown: each step up doubles the work for an attacker. This is the recommended choice. The bcrypt algorithm caps the password at 72 bytes — anything longer is silently ignored, exactly as Apache does.
  • APR1-MD5 (htpasswd -m) — Apache's portable default. It takes a salt of up to 8 characters and runs the Apache Portable Runtime's 1,000-round MD5 mixing (apr_md5_encode), then encodes the digest with Apache's custom base64 ordering to produce $apr1$<salt>$<22-char digest>. Salted, but fast to compute, so weaker than bcrypt against modern cracking hardware.
  • SHA-1 (htpasswd -s) — computes SHA1(password), base64-encodes the 20-byte digest, and prefixes {SHA}. It is unsalted by design, which means identical passwords always produce identical hashes — flagged here as insecure and offered only for compatibility with legacy files.

Every salt is drawn from the browser's cryptographic random source (crypto.getRandomValues), not Math.random. Because bcrypt and APR1-MD5 re-salt on each run, the hash text changes every time — that is expected and is why salted schemes can only be checked by re-running the algorithm, which is exactly what the Verify tab and your web server do. The APR1-MD5 implementation here is reconciled byte-for-byte against openssl passwd -apr1 and the published Apache source, and the SHA-1 output matches the canonical digest of the input.

Worked examples

SHA-1 — reconciles by hand

  1. Username "admin", password "password", algorithm SHA-1.
  2. SHA1("password") = 5baa61e4c9b93f3f0682250b6cf8331b7ee68fd8 (20 bytes).
  3. base64 of those 20 bytes = W6ph5Mm5Pz8GgiULbPgzG37mj9g=
  4. Output line: admin:{SHA}W6ph5Mm5Pz8GgiULbPgzG37mj9g=
  5. This equals the published SHA-1 digest of "password" exactly.

APR1-MD5 — matches openssl

  1. Password "myPassword", fixed salt "rqXexS6Z" (the tool uses a random salt).
  2. Run apr_md5_encode: MD5(pw+salt+pw), fold in the password length bit-pattern, then 1,000 mixing rounds.
  3. Apache base64 of the final digest = QK/GOWpcYWrvXocW5.iZu1
  4. Output: $apr1$rqXexS6Z$QK/GOWpcYWrvXocW5.iZu1
  5. Identical to `openssl passwd -apr1 -salt rqXexS6Z myPassword`.

bcrypt — verify, don't compare

  1. Password "password", cost 10, salt N9qo8uLOickgx2ZMRZoMye.
  2. Output: $2y$10$N9qo8uLOickgx2ZMRZoMye8fOsiTWZqYtkxvXkKm8BMzjT7t/vIdq
  3. Paste that hash + "password" into the Verify tab → matches.
  4. Paste the same hash + "password1" → no match.
  5. A live run produces a different salt each time, so check by verifying, not by string equality.

Frequently asked questions

Sources & references

Related tools

Rate this tool
Be the first to rate

Comments & feedback

Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.

Found a bug, edge case, or want to suggest an improvement?

Email me at [email protected] — most fixes ship within 24 hours.