Menu

1 / 5

Layered login defence: rate limits, lockout and captcha

DEV Community: authentication·Mohammad Khalifeh·13 days ago
#O4ZGvaNO
#devtoauthentication#devto#dev#password#login
Long article (517 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.