A login form is the one page on a site that attackers are guaranteed to try. Most attacks are not clever. They are scripts that try common passwords, or passwords leaked from other sites, as fast as the server answers. No single defence stops all of them, so I layer several cheap ones.
1. Rate limit by IP
ASP.NET Core has a built-in rate limiter. A fixed window of around ten attempts per IP per fifteen minutes stops naive scripts without bothering a real person who mistyped twice.
options . AddPolicy ( "admin-login" , context => RateLimitPartition . GetFixedWindowLimiter ( context . Connection . RemoteIpAddress ? . ToString ( ) ?? "unknown" , _ => new FixedWindowRateLimiterOptions { PermitLimit = 10 , Window = TimeSpan . FromMinutes ( 15 ) } ) ) ;
Enter fullscreen mode
Exit fullscreen mode
Behind a proxy or CDN, make sure the forwarded headers middleware is configured, or every visitor will share the proxy's address.
2.…