Backup and Security

WordPress Login Security: Rate Limiting, Custom URL, and Brute Force Protection

Stop WordPress brute force attacks in layers: two-factor, server rate limits, a tested login throttle, and an honest look at custom login URLs.

Varun DubeyVarun Dubey
·12 min read
Server log lines showing three POST requests to wp-login.php answered 200 and two blocked with 429 under the headline Stop the flood before it reaches PHP

The most effective WordPress login protection is a layered one: a unique long password and two-factor authentication stop an account from being taken over, rate limiting at the server or CDN stops the flood, and a small PHP throttle is the last line when the first two are missing. A custom login URL is the weakest layer. It cuts log noise, but it does not stop anyone who already knows or guesses your username.

We rebuilt this guide on 16 November 2026. The earlier version contained a PHP lockout that, as written, would not have blocked a correct password, so we checked the authentication flow in WordPress core, fixed the code, and ran it through a small test script. Everything below was checked against the WordPress core source, developer documentation, the WordPress.org plugin directory and the NIST password guidance on that date.

Who this is for: developers and site owners who can edit wp-content/mu-plugins or a server config. If you manage the site from a dashboard only, skip to the plugin and two-factor sections.

The short version

  • Turn on two-factor for every account that can publish or manage. This beats every lockout rule, because a guessed password alone no longer gets in.
  • Rate limit at the edge. Cloudflare rules, nginx limit_req or fail2ban stop requests before PHP starts. A PHP throttle still loads all of WordPress for every attempt.
  • If you throttle in PHP, hook authenticate at priority 100. Core’s own password check runs at 20. A lockout hooked earlier is overwritten and does nothing.
  • Count the client IP correctly. Behind a proxy, REMOTE_ADDR is the proxy. Fix that at the server, not by trusting a header the visitor can forge.
  • Treat a custom login URL as noise control. Keep the recovery steps written down before you use one.
  • Close the side doors. XML-RPC, application passwords and the REST API accept credentials without wp-login.php.

How does a brute force attack on WordPress actually work?

A bot sends a username and password to a login endpoint and checks the response. It repeats this thousands of times with guesses from a leaked-password list or from your own author names. Most attacks are not guessing at random. Credential stuffing reuses real email and password pairs from other breaches, hoping you reused yours.

Three entry points accept credentials, and a login defence has to cover all of them:

Entry point

What it accepts

Covered by a wp-login.php-only rule?

/wp-login.php

Username or email and password via a form POST

Yes

/xmlrpc.php

Username and password inside XML requests, including many guesses per request through system.multicall

No

REST API with application passwords

A username and an application password in an HTTP Basic header

No

Passwords on the server side are stored better than they used to be. The WordPress core team switched password hashing from phpass to bcrypt in WordPress 6.8, with SHA-384 pre-hashing and a $wp$2y$ prefix. Existing users are rehashed on their next login. That makes a stolen hash far more expensive to crack, but it does nothing against an attacker who guesses the live password through the login form. Hashing protects the database. Rate limiting and two-factor protect the front door.

If you want the wider picture of what else to check on a site, our five-minute security audit covers certificates, headers, exposed files and administrator accounts.

Where should login rate limiting live?

As far from PHP as you can put it. Every request that reaches WordPress costs a PHP process, a database connection and a plugin load. A distributed attack can exhaust workers long before it guesses anything. The layers below are listed from best to last resort.

Layer

Stops the request before PHP?

Setup effort

Main drawback

CDN or WAF rule (for example Cloudflare rate limiting)

Yes

Low, in a dashboard

Rules and limits depend on your plan

Web server (limit_req in nginx)

Yes

Medium, config file

Per-IP only, and needs the real client IP behind a proxy

fail2ban reading the access log

Yes, after a few attempts

Medium

Needs log access and the real client IP in the log

PHP throttle in a mu-plugin

No

Low, one file

Loads WordPress for every attempt

Security plugin

No

Lowest

Same PHP cost, plus another plugin to keep updated

None of these replace the others. The PHP layer is worth having on shared hosting where you cannot edit the web server, and the web server layer is worth having everywhere you can.

How do I rate limit WordPress logins with a small mu-plugin?

Save the file below as wp-content/mu-plugins/login-throttle.php. It counts failed logins per IP address in a transient. After five failures in fifteen minutes, that IP gets an error for every login attempt, even with a correct password, until the window passes.

<?php
/**
 * Plugin Name: Login Throttle
 * Description: Blocks an IP address for a while after repeated failed logins.
 */

defined( 'ABSPATH' ) || exit;

const TWP_LOGIN_MAX_FAILS = 5;                   // failures allowed per window
const TWP_LOGIN_WINDOW    = 15 * MINUTE_IN_SECONDS; // counter and lockout length

function twp_login_key(): string {
	$ip = isset( $_SERVER['REMOTE_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : '';
	return 'twp_lf_' . md5( $ip );
}

// Count every failure. Core fires this for any login error except an empty field.
add_action(
	'wp_login_failed',
	function () {
		$key = twp_login_key();
		set_transient( $key, (int) get_transient( $key ) + 1, TWP_LOGIN_WINDOW );
	}
);

// Priority 100 runs after core's own handlers (20 and 99), so this error is the final answer.
add_filter(
	'authenticate',
	function ( $user ) {
		if ( (int) get_transient( twp_login_key() ) >= TWP_LOGIN_MAX_FAILS ) {
			return new WP_Error(
				'twp_login_locked',
				__( '<strong>Error:</strong> Too many failed attempts. Try again in a few minutes.' )
			);
		}
		return $user;
	},
	100
);

Four details decide whether this works:

  • Why priority 100. In current core, wp_authenticate_username_password, wp_authenticate_email_password and wp_authenticate_application_password run on authenticate at priority 20, and wp_authenticate_spam_check at 99. The username and password handler starts with if ( $user instanceof WP_User ) return $user; and otherwise checks the credentials itself, so an error you return earlier is simply replaced by a valid login. Hooking at 100 makes your error the final answer. Treat any lockout snippet that hooks at priority 1 with suspicion, including the earlier version of this post.
  • Blocked attempts count too. Core fires wp_login_failed with the username and the error for every login error except an empty username or password. Your own lockout error triggers it, so a bot that keeps hammering stays locked out. A real user on the same IP waits until the bot stops, which is the trade-off of per-IP counting.
  • The IP is REMOTE_ADDR only. Headers such as X-Forwarded-For can be set by anyone, so trusting them lets an attacker rotate fake addresses and never reach the limit. If your site sits behind Cloudflare or a load balancer, configure the web server to restore the real client address into REMOTE_ADDR from the proxy’s published ranges. The plugin vendors say the same in their docs, as the mistakes list below shows.
  • Where the counter lives. Without a persistent object cache, transients are rows in the options table, so every failed login is a database write. That is acceptable for a login page and a reason to prefer the edge layers for heavy traffic.

We checked the file with php -l on PHP 8.5.5 and ran its two callbacks against a small test script that mimics core’s flow, with the transients stubbed out. Results from the test script: failures 1 to 5 returned the normal authentication error, failures 6 and 7 returned twp_login_locked, a correct password from the locked IP was refused, and a different IP with a correct password got in. We did not run it against a live WordPress install for this refresh, so test it on staging with a throwaway account before you rely on it.

# checked on 16 Nov 2026 - run against a staging site you own
for i in 1 2 3 4 5 6 7; do
  curl -s -o /dev/null -w "attempt $i: %{http_code}\n" \
    -d 'log=testuser&pwd=wrong-password' https://staging.example.com/wp-login.php
done
# every attempt returns 200 because the form is shown again; read the page text for the lockout error

Unlock an address during testing by deleting its counter. Transient keys are hashed, so the simple route is to flush the transients on staging:

wp transient delete --all

How do I rate limit logins in nginx or with fail2ban?

Use limit_req for a hard per-IP ceiling and fail2ban for temporary bans. Both stop the request before PHP starts. The nginx pattern below limits the login URL to a slow trickle per address and allows a short burst so a real person who mistypes is not punished.

# http { } context
limit_req_zone $binary_remote_addr zone=wplogin:10m rate=30r/m;
limit_req_status 429;

# server { } context
location = /wp-login.php {
    limit_req zone=wplogin burst=5 nodelay;
    # keep your usual PHP handling here (include fastcgi_params; fastcgi_pass ...)
}

rate=30r/m is one request every two seconds on average. burst=5 nodelay lets five extra requests through immediately and rejects the ones beyond that with the status code you set. These are standard directives of the nginx rate limiting module, which you can read about in the nginx documentation. Test with nginx -t before reloading, and check that the real client address reaches nginx first. If everything arrives from your CDN, the whole world shares one counter.

For fail2ban, the useful signal is the response code. A failed WordPress login shows the form again with HTTP 200, while a successful login redirects with 302. A filter that matches only POSTs answered with 200 therefore counts failures, not successes.

# /etc/fail2ban/filter.d/wordpress-login.conf
[Definition]
failregex = ^<HOST> .* "POST /wp-login\.php[^"]*" 200

# /etc/fail2ban/jail.d/wordpress-login.local
[wordpress-login]
enabled  = true
port     = http,https
filter   = wordpress-login
logpath  = /var/log/nginx/access.log
maxretry = 5
findtime = 600
bantime  = 3600

We tested the regular expression against sample access-log lines in the combined format: it matched two POST requests answered 200 and skipped a POST answered 302 and a GET. We did not run fail2ban itself. Check it on your own log with fail2ban-regex /var/log/nginx/access.log /etc/fail2ban/filter.d/wordpress-login.conf before you enable the jail.

To see whether you are being attacked at all, count failed login POSTs per address from the access log:

# checked on 16 Nov 2026 - combined log format, tested on sample lines
awk '$6=="\"POST" && $7 ~ /^\/wp-login\.php/ && $9==200 {print $1}' access.log \
  | sort | uniq -c | sort -rn | head

Does changing the WordPress login URL improve security?

It reduces noise and nothing else. A hidden login URL does not slow an attacker who has your username and a way to reach another entry point such as XML-RPC. What it does do is remove the thousands of automated hits on /wp-login.php that clutter logs and burn PHP time, which is a real if modest benefit.

The simplest route is a plugin. WPS Hide Login shows 2+ million active installs on its WordPress.org page. Its API data on 16 November 2026: version 1.9.20, last updated 12 November 2026, tested up to WordPress 7.2, 4.8 stars from 2,113 ratings, 0 of 2 support threads resolved in the last two months. Its description says the wp-admin directory and wp-login.php page become inaccessible, so you must bookmark the new URL.

What happens if I forget the custom login URL?

The plugin FAQ gives two ways back. Read the whl_page option from the options table (on multisite it can be in the sitemeta table), or remove the wps-hide-login folder from the plugins directory, log in at the normal address and reinstall it.

# checked on 16 Nov 2026 against the plugin FAQ
wp option get whl_page
# multisite: wp network meta get 1 whl_page
# last resort: wp plugin deactivate wps-hide-login

Write the new URL into your password manager before you save it. Also check password reset emails, logout links and any plugin that links to wp-login.php after the change, because those are where hidden-URL setups usually break.

We did not write a rewrite-rule version for this refresh. A hand-rolled login URL has to cover reset links, logout, post-password forms and every plugin that builds login links, and that is a lot of surface to get wrong. The plugin exists because that work is tedious.

What password and lockout rules should I set?

Require length, check against known breached passwords and drop forced complexity. The NIST digital identity guidelines (SP 800-63B-4) say a password used as a single factor must be at least 15 characters, and that verifiers must not impose other composition rules such as mixed character types. They also require comparing a new password against a blocklist of commonly used and compromised passwords. For throttling, the same document caps consecutive failed attempts per account at 100 as an upper bound, and says organisations may set lower limits.

WordPress core has no breached-password check. Core’s strength meter is advice, not a rule. For a team site the practical move is a password manager for everyone and two-factor on top, which makes the exact password policy matter less.

How do I add two-factor authentication to WordPress?

Install the Two Factor plugin and make each user set up a provider in their profile. It is built by WordPress contributors for exactly this job. On 16 November 2026 the WordPress.org API showed version 0.17.0, last updated 28 September 2026, tested up to 7.1.4, 100,000+ active installs and 4.8 stars from 209 ratings, with 4 of 6 support threads resolved.

Plan the recovery path before you switch it on. Give every user backup codes, keep one second administrator who can reset another’s second factor, and know the emergency route: with WP-CLI you can deactivate the plugin to let people back in.

# emergency only - removes the second factor for everyone while it is off
wp plugin deactivate two-factor

Start with administrators and editors, then anyone who can install plugins or touch payments. Subscribers rarely need it unless your site holds personal data about them.

How do I lock the side doors: XML-RPC, application passwords and the REST API?

Switch off what you do not use, and rate limit what you keep. XML-RPC and application passwords accept credentials without ever loading the login form, so a wp-login.php rule does not cover them.

// mu-plugin. Checked against developer.wordpress.org on 16 Nov 2026.
add_filter( 'xmlrpc_enabled', '__return_false' );

// Only if nothing on the site uses application passwords or remote REST clients:
add_filter( 'wp_is_application_passwords_available', '__return_false' );

Both filters are documented in the WordPress developer reference. Disabling XML-RPC through the filter still lets the file load, so many sites also deny the file at the web server. Before you do, check whether Jetpack or the WordPress mobile app is connected, because they can depend on it. Our guide to disabling XML-RPC and stopping user enumeration walks through both the trade-offs and the author-name leak through the REST API.

List application passwords for an administrator with wp user application-password list <user>, and revoke any you do not recognise. A forgotten application password is a permanent login that survives a password change.

Accounts are the other half of this. If a compromise has already happened, the hidden admin account audit shows how to find an account an attacker left behind.

Which login security plugins are worth a look?

If you would rather install than configure, these four are the ones we checked. The numbers come from the WordPress.org plugin API on 16 November 2026. Ratings are out of 5 stars, support figures are threads resolved out of threads opened in the last two months, and we did not test any of them for this refresh.

Plugin

Active installs

Rating

Last updated

Support resolved

Fits

Two Factor

100,000+

4.8 (209)

28 Sep 2026

4 of 6

Two-factor only, no lockouts

Limit Login Attempts Reloaded

1 million+

4.8 (1,490)

13 Nov 2026

1 of 8

Lockouts, with a configurable IP header

WPS Hide Login

2 million+

4.8 (2,113)

12 Nov 2026

0 of 2

Custom login URL only

Wordfence

5 million+

4.7 (5,051)

10 Nov 2026

151 of 178

Full firewall and scanner plus login rules

Our suggestion: on a small site, use Two Factor plus an edge or server rate limit, and skip the custom login URL unless your logs are unreadable without it. On a site you cannot give server access to, Limit Login Attempts Reloaded covers the lockout need, but set its IP header correctly first. Wordfence suits a site that wants one product for firewall, scanning and login rules, at the cost of a bigger plugin and its own settings to learn. We build WordPress security tooling too, WP Vanguard for scanning and monitoring, but it does not replace login rate limiting, so it is not on this list.

Common mistakes people report

Checked on 16 November 2026. Each one comes from public threads or the core source, paraphrased.

  • Getting locked out by a custom login URL. Users report a 404 on the new address with nothing in the logs, and recover by renaming the plugin folder. See this wordpress.org thread.
  • Everyone locked out at once behind a CDN. When the server reports the proxy’s address, one lockout blocks every visitor. The vendor documents it in its FAQ on all users being blocked, and users describe it in a Cloudflare lockout thread.
  • Trusting a forwarded header. Choosing the wrong IP header lets anyone spoof an address and dodge the limit. Pick the single header your proxy sets, or fix it at the server.
  • A lockout hook that never fires. Hooking authenticate before core’s credential check means your error is replaced. The core handlers are registered at priority 20 in default-filters.php.
  • Protecting wp-login.php and forgetting XML-RPC. The multicall method packs many guesses into one request, so a per-request limit on the login page misses it.
  • Turning on two-factor with no recovery plan. The lockout lands on the person who owns the site. Keep backup codes and a second administrator.

Frequently asked questions

What is the best way to stop brute force attacks on WordPress?

Two-factor authentication for privileged users, plus rate limiting at the CDN or web server. Add the PHP throttle only where you cannot reach the server layer.

How many failed logins should lock an IP address?

Five failures in ten to fifteen minutes is a common starting point. NIST’s upper bound is 100 consecutive failures per account, and organisations may choose lower. Pick the number from how often your real users mistype, then watch the logs.

Does a login limiter slow my site?

A PHP limiter adds a transient read to each login attempt and a write on each failure. Without an object cache that is a database query. Edge and server limits cost almost nothing because they reject the request first.

Should I block wp-login.php by IP address instead?

If your admins have fixed addresses, yes: an allow list at the web server is stronger than any counter. Most teams move around, so it is rarely practical, and it must not break password reset or front-end login forms.

Do I still need a limiter if I have two-factor on?

Yes, for load. Two-factor stops the takeover, but a bot can still send thousands of requests. A limiter keeps those requests from using your PHP workers.

Can I rate limit the REST API and XML-RPC the same way?

Yes at the web server or CDN. Match the paths /xmlrpc.php and /wp-json/ in a rule. The mu-plugin above protects login attempts that pass through WordPress’s authentication, so it also sees failed XML-RPC logins.

Is a custom login URL safe with caching?

Make sure your cache or CDN does not cache the new login path and does not skip the bypass rules you set for wp-login.php. Test a login after enabling it.

What if I lock myself out with the mu-plugin?

Wait for the window to pass, log in from another IP, or delete the file by SFTP. It lives in wp-content/mu-plugins, so removing it takes effect immediately.

How we checked this

WordPress core behaviour came from the current development source on 16 November 2026 (default-filters.php, pluggable.php and user.php, development version 7.2 beta). The mu-plugin was linted on PHP 8.5.5 and exercised against stubs, not a live site. The fail2ban regular expression and the awk command were run against sample log lines. nginx and fail2ban configuration were not run on a live server. Plugin figures are from the WordPress.org API, NIST figures from SP 800-63B-4, and the bcrypt details from the WordPress core team’s announcement.

If you want a developer to put these layers in place and test them on a real server, our services team does that for client sites. It is one option, so compare scope and price before you choose.

Part of the Wbcom Designs family

The all-in-one WordPress community stack

Also ours: wbcomdesigns.comvapvarun.combrndle.com