Why failed logins matter for WordPress
WordPress sites are frequent targets for credential‑stuffing and brute‑force attacks. Because these attempts are automated and often distributed (botnets), even unsuccessful attacks can overwhelm your site with requests. When thousands of login requests hit wp-login.php in a short period, the web server can become saturated, slowing down legitimate visitors and consuming bandwidth. In addition, each failed attempt gives an attacker another chance to guess a password, increasing the risk of a successful compromise.
The primary defensive goal is to make it expensive for bots while keeping the login experience smooth for real users. This means limiting how often a single IP can try to authenticate, adding challenges that only humans can solve, and reducing the attack surface of WordPress core endpoints such as XML‑RPC. The steps below walk through each of these layers, with concrete commands, file edits, and screenshots of the WordPress admin where applicable.
When you implement a limit—such as blocking an IP after five failures—you should see the offending address disappear from your access logs and the site’s response time improve. Conversely, a common mistake is to set the limit too low, which can lock out legitimate users behind shared NATs; always test with a secondary account before deploying site‑wide. Also, relying solely on a single layer (e.g., only a CAPTCHA) leaves other vectors open; combine rate limiting, IP blocking, and endpoint hardening for a defense‑in‑depth posture.
Rate‑limit at the edge or server
Rate‑limit login attempts at the edge (WAF/CDN) or the web server. Edge rate limiting stops traffic before it reaches your WordPress installation, conserving resources and protecting the underlying infrastructure.
Using a CDN/WAF (e.g., Cloudflare)
- Log in to your CDN dashboard.
- Navigate to Firewall → Tools → Rate Limiting.
- Create a new rule:
- URI:
*/wp-login.php* - Method:
POST - Threshold: 1 request per 10 seconds (default edge limit).
- Action:
Blockfor 1 hour. - Response: custom “Too many login attempts” page.
- URI:
- Save the rule.
When the rule works you will see the rule listed with a green checkmark, and the dashboard will display the number of requests blocked each day.
After enabling, attempt more than one POST to the login page within ten seconds from the same IP; the CDN should return the custom block page and the request will never reach your origin server. A common error is to apply the rule to GET instead of POST, which would block legitimate page views of the login form.
Apache with mod_ratelimit
If you cannot use a CDN, enable mod_ratelimit and add a rule in .htaccess located in the WordPress root:
# BEGIN login rate limit
<IfModule mod_ratelimit.c>
<LocationMatch "/wp-login.php">
SetEnvIf Request_Method POST LOGIN_ATTEMPT
SetEnvIf Remote_Addr ^(.*)$ LOGIN_IP=$1
# Limit to 1 request per 10 seconds per IP
RatelimitRequestBody 1024
Header set X-RateLimit-Remaining "1"
Header set X-RateLimit-Reset "10"
</LocationMatch>
</IfModule>
# END login rate limit
The unsafe version would omit the LocationMatch block, allowing unlimited POST requests to wp-login.php. Adding the block restricts POST traffic and adds headers that can be inspected in server logs to verify the limit is active.
To confirm, send three rapid POST requests from the same client. The first should succeed, while the second and third will receive a truncated response and the X-RateLimit-Remaining header will show 0. Check Apache’s access log; you should see a 403 or 429 status for the throttled requests. A frequent mistake is forgetting to restart Apache after enabling mod_ratelimit, which leaves the directives ineffective.
Nginx with limit_req
For Nginx, edit the server block for your site (usually in /etc/nginx/sites-available/example.com):
# BEGIN login rate limit
limit_req_zone $binary_remote_addr zone=login:10m rate=6r/m;
server {
...
location = /wp-login.php {
limit_req zone=login burst=2 nodelay;
include fastcgi_params;
fastcgi_pass unix:/var/run/php/php-fpm.sock;
}
...
}
# END login rate limit
After reloading Nginx (sudo nginx -s reload), attempts beyond six per minute from the same IP are delayed or dropped, depending on the burst setting. Check the Nginx error log for messages like “client exceeded request rate limit”.
Test by using a tool such as curl in a loop: for i in {1..8}; do curl -X POST -d "log=admin&pwd=wrong" https://example.com/wp-login.php; done. The last two requests should be rejected with a 429 status, and the error log will record the limit breach. A common oversight is to place the limit_req_zone directive outside the http block, which causes Nginx to ignore the rule entirely.
Add a CAPTCHA or Turnstile to the login form
Put a CAPTCHA/turnstile on login to slow bots (e.g., Cloudflare Turnstile, reCAPTCHA). Adding a challenge after a failed attempt or on every login request forces automated scripts to solve a puzzle they cannot.
Using Cloudflare Turnstile (free)
- Register a Turnstile site at the Cloudflare dashboard and obtain Site Key and Secret Key.
- Install the free plugin “Turnstile for WordPress” (available in the repo).
- In Settings → Turnstile, paste the keys and enable the toggle for “Login form”.
- Save changes.
When the configuration works, the login page will display the Turnstile widget just above the “Log In” button. Submitting without solving the widget returns the error “Please complete the challenge”.
To verify, open an incognito window, go to the login page, and attempt to submit the form without interacting with the widget. You should see the error message, confirming that the verification step is enforced. A typical mistake is to leave the “Test mode” enabled after deployment; in test mode the widget always passes, which defeats its purpose.
Using Google reCAPTCHA
- Go to the reCAPTCHA admin console, create a new site, choose “reCAPTCHA v2 – Checkbox”.
- Install the plugin “Login reCAPTCHA”.
- In Settings → Login reCAPTCHA, insert the Site and Secret keys, then enable for the login form.
Login reCAPTCHA is included in the Basic, Pro and Agency plans, so if you are on one of those plans you already have the feature available.
After activation, the login form will show the familiar “I’m not a robot” box. Test by attempting a login with the checkbox unchecked; the plugin should stop the request and display an error like “Please complete the reCAPTCHA”. A common error is to place the keys in the wrong fields (site key vs secret key), which results in the widget loading but always failing verification.
Manual integration (code)
If you prefer a code‑only solution, add the following to your theme’s functions.php:
add_action( 'login_form', function() {
echo '<div class="g-recaptcha" data-sitekey="YOUR_SITE_KEY"></div>';
wp_enqueue_script( 'recaptcha', 'https://www.google.com/recaptcha/api.js', [], null, true );
} );
add_filter( 'authenticate', function( $user, $username, $password ) {
if ( isset( $_POST['g-recaptcha-response'] ) ) {
$response = wp_remote_post( 'https://www.google.com/recaptcha/api/siteverify', [
'body' => [
'secret' => 'YOUR_SECRET_KEY',
'response' => $_POST['g-recaptcha-response'],
'remoteip' => $_SERVER['REMOTE_ADDR'],
],
] );
$result = json_decode( wp_remote_retrieve_body( $response ) );
if ( empty( $result->success ) ) {
return new WP_Error( 'captcha_failed', __( '<strong>Error</strong>: CAPTCHA verification failed.' ) );
}
}
return $user;
}, 30, 3 );
The unsafe version would omit the wp_remote_post verification, allowing any POST to bypass the CAPTCHA. The corrected version validates the token with Google and returns an error when verification fails.
After adding the code, clear any caching plugins and reload the login page. You should see the reCAPTCHA widget. Attempt a login without solving it; the error message defined in the WP_Error object should appear, confirming the server‑side verification is active. A frequent slip is to forget to enqueue the script, which results in an empty placeholder and allows the form to submit unchecked. Ensure the script tag appears in the page source and that the verification request reaches Google’s endpoint.
Harden XML‑RPC and the login URL
Protect or disable XML‑RPC if you don’t need it; otherwise restrict and rate‑limit it. XML‑RPC provides a remote authentication endpoint (/xmlrpc.php) that many bots exploit for brute‑force attempts.
Disable XML‑RPC completely
Add the following to your site’s functions.php or a site‑specific plugin:
add_filter( 'xmlrpc_enabled', '__return_false' );
When disabled, a request to https://example.com/xmlrpc.php returns a 403 Forbidden response. Verify by visiting the URL; you should see a “Forbidden” message.
If you later need to re‑enable it, simply remove or comment out the filter line. A mistake people make is to place the code inside a conditional that never runs (for example inside an if ( is_admin() ) block), which leaves XML‑RPC unintentionally active.
Restrict XML‑RPC to known IPs
If you need XML‑RPC for a mobile app, limit it with .htaccess:
<Files xmlrpc.php>
Order Deny,Allow
Deny from all
Allow from 203.0.113.10
Allow from 198.51.100.22
</Files>
Replace the IPs with those of your trusted devices. The unsafe version would omit the Deny from all line, leaving the file publicly accessible.
After saving the file, test by curling the endpoint from an allowed IP (curl -I https://example.com/xmlrpc.php) and from a non‑allowed IP. The allowed request should return 200 OK (or the XML‑RPC response), while the other should return 403 Forbidden. A frequent error is forgetting to restart Apache after editing .htaccess; while most changes take effect immediately, a mis‑configured directive can cause a 500 error instead of a block.
Rate‑limit XML‑RPC via Nginx
Add a separate rate‑limit zone:
limit_req_zone $binary_remote_addr zone=xmlrpc:10m rate=2r/m;
location = /xmlrpc.php {
limit_req zone=xmlrpc burst=1 nodelay;
fastcgi_pass php-fpm;
}
Now each IP can make only two XML‑RPC calls per minute, dramatically reducing the effectiveness of password‑spraying scripts.
Reload Nginx (sudo nginx -s reload) and then issue several rapid XML‑RPC requests from the same IP. After the second request, subsequent attempts should be logged as “client exceeded request rate limit” and the response will be a 429 Too Many Requests. A common misstep is to set the rate too high (e.g., 10r/m) which does not provide meaningful protection; keep it low enough to block automated bursts but high enough for legitimate use.
Obscuring the login URL
Obscuring the login URL can reduce noise but should not be your only defense. Plugins such as WPS Hide Login change the default wp-login.php to something like /my-secret-login. After activation:
- Go to Settings → General.
- Scroll to Login URL and type a new slug (e.g.,
admin-access). - Save changes.
When successful, navigating to the old URL returns a 404, while the new URL shows the standard login form. Remember to update any bookmarked admin links.
Test the change by manually typing the original wp-login.php URL; you should see the site’s 404 page. Also verify that the new URL loads the login page and that you can still access the dashboard after logging in. A frequent mistake is to change the slug to something that conflicts with an existing page or custom post type, resulting in a “Page not found” error for legitimate users.
Use a security plugin for login throttling when the host lacks edge limits
If your host/CDN doesn’t rate‑limit at the edge, a security plugin can throttle login attempts. Popular choices include Wordfence, iThemes Security, and Shield Security. These plugins add server‑side throttling, IP blacklisting, and optional two‑factor authentication.
Example with Wordfence
- Install and activate Wordfence.
- In Wordfence → Login Security, enable “Limit login attempts”.
- Set “Lockout after” to
5attempts and “Lockout duration” to1 hour. - Enable “Block IP after repeated lockouts” to automatically ban persistent offenders.
After saving, a failed login attempt counter appears next to each username in the Users list. When the limit is reached, Wordfence records the lockout in Tools → Live Traffic and returns a 403 response to the attacker.
To confirm it works, attempt a login with an incorrect password five times from the same IP. On the sixth attempt you should see a message stating that the IP is locked out, and the Live Traffic view will show a new lockout entry with the IP address and timestamp.
A typical mistake is to leave the “Enable reCAPTCHA on login” option unchecked; without a challenge, bots can still hammer the endpoint until the lockout threshold is met, which may give them enough tries to guess weak passwords.
Example with iThemes Security
- Install iThemes Security.
- Go to Security → Settings → Brute Force Protection.
- Turn on “Enable Brute Force Protection” and set “Maximum login attempts” to
5. - Choose “Lockout Period” of
60minutes.
The plugin writes a rule to .htaccess that looks like:
# iThemes Security - Brute Force Protection
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^/wp-login\.php$
RewriteCond %{REMOTE_ADDR} ^(.*)$
RewriteRule ^ - [E=ITSEC_BRUTE_FORCE:%1]
</IfModule>
When the rule works, the ITSEC_BRUTE_FORCE environment variable is set for blocked IPs, and the server returns a 403 page.
You can test the rule by sending a POST request to wp-login.php with an invalid password repeatedly. After the fifth attempt, the server should immediately return a 403 status, and the .htaccess file will contain the new block. A common oversight is to place the rule above existing WordPress rewrite rules, which can cause the login page to break entirely; always insert it after the # BEGIN WordPress block.
Monitor logs and block abusive IPs
Regularly auditing your WordPress logs is the first line of defense against repeated failed login attempts. Begin by locating the authentication logs that WordPress writes. If you have the default logging enabled, the information appears in the web server’s access log (for Apache usually /var/log/apache2/access.log, for Nginx /var/log/nginx/access.log). Look for requests that target wp-login.php with a POST method and that return a 200 status code – these are typical failed login attempts. You can also enable the built‑in WordPress logging feature through a plugin or by adding define( 'WP_DEBUG_LOG', true ); to wp-config.php; the log file will then be created at wp-content/debug.log. When a pattern emerges—such as a single IP address generating dozens of failures in a short window—you should add that IP to a temporary blocklist to stop the flood.
Using WP‑CLI to list recent failures
wp user list --field=ID,login --format=csv | while IFS=, read id login; do
echo "User: $login"
wp log list --type=failed_login --user=$id --format=table
done
The command prints a table of timestamps and IP addresses for each user. Successful output shows rows like:
+---------------------+-----------+
| time | ip |
+---------------------+-----------+
| 2026-11-30 14:22:05 | 203.0.113.55 |
+---------------------+-----------+
If you see many entries from a single IP, add it to a blocklist.
To manually block the offending IP on a Linux server, edit /etc/hosts.deny and add a line such as ALL: 203.0.113.55. After saving, attempts from that address will be rejected at the TCP level. Verify the block by trying to access the login page from the blocked IP; you should receive a connection timeout or immediate denial.
Fail2ban configuration for WordPress
Create /etc/fail2ban/filter.d/wordpress.conf:
[Definition]
failregex = <HOST> - - \[.*\] "POST /wp-login.php HTTP/.*" 200
ignoreregex =
Create /etc/fail2ban/jail.local entry:
[wordpress-login]
enabled = true
port = http,https
filter = wordpress
logpath = /var/log/apache2/access.log
maxretry = 5
bantime = 3600
Restart Fail2ban (sudo systemctl restart fail2ban). When an IP exceeds five failed POSTs to wp-login.php, it is banned for one hour. Verify with fail2ban-client status wordpress-login.
A common mistake is pointing logpath at the wrong file (for example the error log instead of the access log). If Fail2ban cannot read the expected patterns, it will never trigger a ban. Double‑check the path and ensure the web server rotates logs in a way that Fail2ban can follow.
Using the internal security checker
Run the Free website security checker from your dashboard or visit /security-checker on your site. The tool scans for open XML‑RPC, default login URL, and missing CAPTCHA. When the scan passes, you will see a green “All checks passed” badge.
If the badge is missing, the checker will list each failing item with a link to the relevant settings page. Click those links, apply the suggested changes, and re‑run the scan. The successful state is indicated by the green badge and a summary that no critical issues were detected.
Common mistakes and troubleshooting
Forgetting to clear caches
After adding a CAPTCHA or changing the login URL, page caches (e.g., Varnish, plugin caches) may still serve the old wp-login.php. Purge the cache from your CDN or caching plugin, then reload the login page to confirm the new form appears.
Misconfigured rate limits blocking legitimate users
If you set the threshold too low, users on slow connections may be blocked after a single retry. Test by attempting a login from a different network or using a VPN. Adjust the burst parameter in Nginx or the “Lockout after” count in your security plugin until genuine users can log in without hitting the limit.
Overlooking XML‑RPC in the REST API
Even when xmlrpc.php is disabled, some plugins expose XML‑RPC functionality through the REST API. Scan the site with the Free website security checker or manually request https://example.com/wp-json/wp/v2/users and verify that unauthenticated requests do not return password‑hash data. If they do, disable the offending plugin or add a REST authentication filter.
CAPTCHA not loading
A missing site key or blocked script from the CDN will cause the CAPTCHA widget to disappear, leaving the login form unprotected. Open the browser console (F12) and look for 404 or CSP errors related to turnstile or recaptcha. Re‑enter the correct keys in the plugin settings and ensure the script URLs are whitelisted in any content‑security policy.
Edge rate limiting not applied
Some CDNs require you to enable “Rate Limiting” per plan. Verify that “Rate limiting is included in every plan, including Free.” In the dashboard, check the rule status; it should be Active. If the rule shows Paused, activate it and re‑test by sending rapid login requests with a tool like curl.
Plugin conflicts
Two plugins that both modify wp-login.php (e.g., a custom login URL plugin and a CAPTCHA plugin) can cause the form to break. Deactivate one plugin, test the login flow, then reactivate the other. The order of activation matters; usually the URL‑obfuscation plugin should load first, followed by the CAPTCHA plugin.
By systematically checking these common pitfalls, you can maintain a robust defense against WordPress failed login attempts without disrupting legitimate access.
Further reading
- For a deep dive into brute‑force protection, see the WordPress brute force protection guide.
- Learn more about edge‑based defenses in the Rate Limiting and Bot Protection article.
- Run the Free website security checker to validate your hardening steps.




