- How to set the number of allowed failed logins?
- How to set a blocking period?
The default project template uses the extension method to configure the AddIdentity<TUser, TRole> (in the Startup class ConfigureServices method). There is an overload of this method, which you can configure IdentityOptions .
Instead
services.AddIdentity<ApplicationUser, IdentityRole>() .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders();
you can use
var lockoutOptions = new LockoutOptions() { AllowedForNewUsers = true, DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5), MaxFailedAccessAttempts = 5 }; services.AddIdentity<ApplicationUser, IdentityRole>(options => { options.Lockout = lockoutOptions; }) .AddEntityFrameworkStores<ApplicationDbContext>() .AddDefaultTokenProviders();
The above does not make sense, since these are the default values โโof LockoutOptions , but you can change them as you wish.
source share