How to Protect Your WordPress Login Page from Brute-Force Attacks
Every WordPress site has the same front door: wp-login.php. Bots find it soon after a site goes live and start trying username and password combinations, one after another, until something works or the server gives up. The good news is that you can protect WordPress login brute force attempts with a few layers that cost nothing and take less than an hour to set up. This guide covers the fixes that matter most: strong credentials, a limit on login attempts, a Fail2ban filter, XML-RPC turned off, two-factor authentication, and a Cloudflare rule in front of the login page. Work through the steps in order, and test each one before moving on.
What a Brute-Force Attack on wp-login.php Looks Like
A brute-force attack is simple. A bot sends POST requests to wp-login.php with a list of common usernames and passwords, trying each pair until one succeeds. The classic target is the username “admin” with passwords like “password123” or “letmein”. The bot does not need to be smart. It just needs time, and a site with a weak password gives it all the time it needs.
Each failed attempt also costs server resources, since WordPress loads PHP and queries the database for every try. You can see the attempts in your web server log. On Nginx, count recent login requests with:
grep "POST /wp-login.php" /var/log/nginx/access.log | wc -l
If that number keeps climbing every day, bots have found your login page. The steps below shut that traffic down, layer by layer.
Use Strong Passwords and a Username That Is Not “admin”
The first fix is the easiest one, and it is also the one most sites skip. Delete the default “admin” account or rename it to something that is not guessable, and give every user on the site a long, random password stored in a password manager. A password of 16 or more random characters stops dictionary attacks cold, because the password is simply not in any word list the bot is trying.
Do not reuse a password from another site. If that other site leaks its passwords, your WordPress login becomes the next thing the bot tries. Every account on your site needs its own password, including accounts for editors and shop managers, not just the admin.
Limit Login Attempts
Limit login attempts so a bot cannot keep guessing forever. After a set number of failed logins from one IP address, that address gets locked out for a while.
The easiest way is a free plugin. Limit Login Attempts Reloaded is a common choice: install it, set the allowed retries to 5, and set the lockout to 20 minutes or more. The plugin also shows you which IPs have been locked out, which is useful when you check the logs later.
If you run your own server, you can enforce the same limit at the web server instead. On Nginx, add a rate limit zone and apply it to the login page:
limit_req_zone $binary_remote_addr zone=login:10m rate=5r/m;
location = /wp-login.php {
limit_req zone=login burst=3 nodelay;
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock;
}
This allows five login requests per minute from one IP, with a burst of three. Real users never notice it. Bots hit the limit within seconds and get a 503 response instead of another password guess. Keep your own IP in mind when you test this, or you will lock yourself out while checking that it works.
Protect WordPress Login Brute Force Attacks with Fail2ban
A login limit plugin slows a bot down, but Fail2ban stops it at the firewall. Fail2ban watches your logs for failed login attempts and bans the attacker’s IP address at the server level, so the requests never reach WordPress at all. Our Fail2ban setup guide for SSH brute-force attacks covers the install and the basic layout, and the same ideas apply here.
Add a jail for the WordPress login page in /etc/fail2ban/jail.local:
[wordpress-login]
enabled = true
port = http,https
filter = wordpress
logpath = /var/log/nginx/access.log
maxretry = 5
findtime = 600
bantime = 3600
This bans an IP for one hour after five failed logins within ten minutes. The wordpress filter ships with Fail2ban, but check that your log format matches what it expects, or the jail will sit there doing nothing. Our guide to Fail2ban jails for SSH, WordPress, and mail services explains how filters and jails work together, and how to test a jail with fail2ban-regex before you trust it. When you set up fail2ban wordpress protection, always test the jail with a few failed logins from a second IP, and confirm the ban shows up in fail2ban-client status wordpress-login before you call it done.
Disable XML-RPC
XML-RPC is an old WordPress feature that lets outside apps talk to your site, and it is also a second login door that most sites never use. The problem is that one request to xmlrpc.php can carry hundreds of login attempts in a single call, using the system.multicall method. A bot that is blocked from hammering wp-login.php can switch to xmlrpc.php and keep guessing through that door instead.
Unless you use the WordPress mobile app or a plugin that needs XML-RPC, turn it off. You can block it at the server with one location block in your Nginx config:
location = /xmlrpc.php {
deny all;
}
Reload Nginx and test that xmlrpc.php returns a 403. Our guide to disable XML-RPC to stop wp-login brute-force attacks walks through the plugin option too, plus how to check whether anything on your site still needs it. To disable xml-rpc safely, check your plugins first: a few Jetpack features and some posting apps use it.
Add Two-Factor Authentication
Two-factor authentication is the layer that saves you when a password fails. Even if a bot guesses the right password, it still cannot log in without the second factor, which is a time-based code from an authenticator app on your phone. This is the single most effective step on this page for accounts that matter.
For two factor authentication wordpress setups, the free plugin Two Factor by the WordPress core team is a solid choice, and Wordfence Login Security adds the same feature with a few extra options. Install one, enable it for every administrator account first, then roll it out to editors. Each user scans a QR code with an app like Google Authenticator or Authy, and from then on the login page asks for the code after the password.
Set this up while you are still logged in, and save the recovery codes the plugin gives you. Without them, losing your phone means editing the database by hand to get back in.
Put Cloudflare in Front of wp-login.php
If your site sits behind Cloudflare, you can block or challenge login attempts before they ever reach your server. A WAF custom rule that matches the wp-login.php path can show a managed challenge to every visitor who tries to open it, or block requests from countries you never log in from. Bots fail the challenge and never reach WordPress. Real admins pass it once and carry on.
A rate limiting rule is useful here too: allow a small number of requests to wp-login.php per minute from one IP, then block the rest for a while. This is the same idea as the Nginx rate limit, but it runs at Cloudflare’s edge, so the traffic never touches your server at all. It is a simple way to protect WordPress login brute force traffic before it reaches your site. Our guide to Cloudflare security settings, WAF rules, Bot Fight Mode, and SSL modes explains where each setting lives and which ones are worth turning on.
Do not block wp-login.php for everyone. Your own team still needs to log in, so use a challenge instead of a hard block, and if you restrict access by country, make sure every admin’s location is allowed.
Check Your Logs and Keep WordPress Updated
The layers above do most of the work, but they are not a reason to stop paying attention. Check the failed login count in your access log once a week. If one IP keeps showing up, ban it by hand or let Fail2ban do it. If the attempts suddenly jump, something changed: a new plugin may have reopened a door, or a rule may have stopped matching after a server update.
Keep WordPress core, your theme, and every plugin updated. Outdated plugins are how most sites actually get in. Delete plugins you no longer use instead of leaving them disabled, and remove old themes too.
To protect WordPress login brute force attempts for the long term, stack the layers: a password no list can guess, a limit on login attempts, Fail2ban banning repeat offenders, XML-RPC closed, two-factor authentication on every admin account, and Cloudflare challenging the login page. No single layer is perfect, but together they make your login page a bad target.