.htpasswd generator for WordPress

Creates a bcrypt .htpasswd line and the Apache rules that put a second password in front of wp-login.php and wp-admin. Hashed in your browser — nothing is sent anywhere.

.htpasswd line · bcrypt $2y$
Choose a username and password, then select Generate.
.htaccess in the WordPress root — above # BEGIN WordPress
# Root .htaccess: ask for the extra password before wp-login.php.
<Files "wp-login.php">
  AuthType Basic
  AuthName "Restricted"
  AuthUserFile "/home/example/.htpasswd"
  Require valid-user
</Files>
wp-admin/.htaccess — optional, protects the whole dashboard
# wp-admin/.htaccess: the same gate for the whole dashboard.
AuthType Basic
AuthName "Restricted"
AuthUserFile "/home/example/.htpasswd"
Require valid-user

# Front-end features call admin-ajax.php, so leave it reachable.
<Files "admin-ajax.php">
  Require all granted
</Files>

How to install it

  1. 01
    Save the line in a file outside the web root.

    Put the generated line in a file such as /home/example/.htpasswd — a directory the web server cannot serve. Add one line per person; each can have their own password.

  2. 02
    Point the rules at that file.

    Enter the file's absolute path above; the rules update to match. Relative paths are resolved against the server root, not the site, which is the most common reason the prompt never accepts a correct password.

  3. 03
    Add the block above WordPress's own rules.

    Paste the first block at the top of the root .htaccess, above # BEGIN WordPress, where WordPress never rewrites it. The .htaccess generator produces the rest of that file.

  4. 04
    Test in a private window.

    Visit /wp-login.php: the browser should ask for this username and password before WordPress's own login form appears.

Apache 2.4 reads bcrypt $2y$ entries natively — the same format htpasswd -B writes. HTTP Basic authentication sends the password with every request, so only use it on a site served over HTTPS. nginx can read the same file with its auth_basic_user_file directive.

Quick answers

Why protect wp-login.php with .htpasswd?

It stops automated password-guessing before it reaches WordPress or PHP at all. Bots hitting the login form get a server-level 401 instead of a login page, which also saves the CPU each attempt would cost.

Will this break anything on the front end?

Protecting only wp-login.php does not. Protecting all of wp-admin can, because themes and plugins call wp-admin/admin-ajax.php from public pages — which is why the generated wp-admin block leaves that one file open.

Which hash format does this use?

bcrypt with the $2y$ identifier, the strongest format Apache's htpasswd supports and the one htpasswd -B produces. Older MD5-based $apr1$ and crypt entries still work in Apache but are far weaker.

Is the password the same as my WordPress password?

It should not be. This is a separate gate in front of WordPress; use a different password so that one leaking does not unlock the other.