Skip to content

Htpasswd generator for Apache (bcrypt and APR1-MD5)

Create the lines of an Apache .htpasswd file to password-protect a folder, staging site or admin page with Basic authentication. Type a username and password, choose bcrypt or APR1-MD5, and copy or download the result. You can also check whether a password matches a line you already have. Hashing happens in your browser, so the password is never sent to this site or anywhere else.

Quick answer

To make an .htpasswd entry, enter the username and password, keep bcrypt selected with cost 10, press Create line, and paste the username:$2y$… line into your .htpasswd file. bcrypt is the strongest format Apache’s htpasswd supports; choose APR1-MD5 only for very old Apache versions or servers that cannot read bcrypt.

Hash format

Hashing runs in your browser. The username, password and lines are never uploaded, logged or saved.

Your .htpasswd lines appear here. They are made on your device.

Apache settings that use the file

AuthType Basic
AuthName "Restricted"
AuthUserFile /etc/apache2/.htpasswd
Require valid-user

Put these lines in the site configuration or in a .htaccess file in the folder to protect, and point AuthUserFile at your .htpasswd, ideally outside the web root. Always serve the site over HTTPS.

How to use the Htpasswd Generator

  1. Type the username and the password, or press Suggest one for a strong random password, and note it somewhere safe such as a password manager.
  2. Keep bcrypt with cost 10, or choose APR1-MD5 if your server cannot use bcrypt, then press Create line. Repeat for each user.
  3. Copy the lines or download them, save them as .htpasswd on your server, and add the Apache settings shown next to the result to the folder you want to protect.

What an .htpasswd file is

Apache’s Basic authentication checks visitors against a plain text file with one user per line, written as the username, a colon and a password hash, for example admin:$2y$10$…. The server never stores the password itself; when someone logs in, it hashes what they typed and compares. The file is usually called .htpasswd and should sit outside the public web folder, so nobody can download it. The same file format is read by many other web servers and hosting control panels.

Why bcrypt is the right choice

If the file ever leaks, attackers will try to guess passwords offline. bcrypt is designed to be slow and adds a random salt, and its cost setting makes each guess more expensive: every step of the cost doubles the work. At cost 10 a modern graphics card manages only thousands of guesses per second, compared with billions for a plain hash. Apache has accepted bcrypt since version 2.4.4, and htpasswd writes it with the $2y$ prefix, which this tool uses too.

Why SHA1, crypt and plain MD5 are weak

The {SHA} format stores an unsalted SHA-1 of the password, so identical passwords give identical lines, and precomputed tables and fast hardware crack common passwords in moments. The old crypt format uses DES, looks only at the first 8 characters and has a tiny salt. APR1-MD5 is better, with a salt and 1,000 rounds of MD5, but MD5 is so fast that a single graphics card can still test millions of guesses a second. That is why this tool does not offer SHA1 or crypt at all, and labels APR1 as the fallback.

Choosing the bcrypt cost

Apache’s htpasswd uses cost 5 by default, which is quick but weak by today’s standards. Cost 10 is a sensible middle ground. Higher costs make each login slower too, because the server repeats the same work on every request that carries the password, and Basic authentication sends it with every page and image. On a busy site, cost 12 or more can add noticeable load. Pick the highest cost your server handles comfortably, and use a long random password: no cost setting rescues a password like admin123.

Usernames, non-English text and long passwords

A username cannot contain a colon, and line breaks would split the file, so the tool blocks both. Arabic letters and emoji work in the file as UTF-8, but browsers differ in how they send them at the login prompt, so plain English usernames are the safe choice. bcrypt reads only the first 72 bytes of a password; an Arabic letter takes two bytes and an emoji four, so the tool warns you when the end of a long password would be ignored.

Privacy and how to check the result

Everything here runs in your browser with bcryptjs, a widely used JavaScript implementation of bcrypt, and an MD5 routine built into the page. Nothing you type is sent, and the site’s analytics record only the format and cost you chose. Each line uses a fresh random salt, so you will never get the same line twice, even for the same password. To confirm a line works before you upload it, switch to Check a line and test the password against it.

Frequently asked questions

Which htpasswd format should I use, bcrypt or MD5?

Use bcrypt whenever your server runs Apache 2.4.4 or later, which is nearly every server today. Choose APR1-MD5 only for an older Apache, or for another server whose system crypt library cannot read $2y$ hashes; it is salted but far faster to crack than bcrypt.

Why are SHA1 and crypt considered weak for .htpasswd?

The {SHA} format has no salt and SHA-1 is extremely fast to compute, so leaked hashes of common passwords fall almost at once. crypt uses only the first 8 characters and old DES. Both are kept in Apache for compatibility, not security, so replace any such lines with bcrypt.

What bcrypt cost should I pick for an .htpasswd file?

Cost 10 suits most sites. Each extra step doubles the time per guess for an attacker and per login for your server. Go up to 12 if the protected area gets little traffic, and stay near 10 on a busy site, since Basic authentication checks the password on every request.

How do I password-protect a folder with the file?

Upload the lines as .htpasswd, ideally outside the public web folder. In the folder’s .htaccess or the site configuration, add AuthType Basic, an AuthName, AuthUserFile with the full path to the file, and Require valid-user. Then serve the site over HTTPS so the password is not sent in the clear.

Why do I get a different line each time for the same password?

Each line includes a new random salt, which is stored inside the hash. That is intentional: it stops attackers from spotting users who share a password or using precomputed tables. Any of the lines will accept the same password, and Check a line confirms it.