1

连续失败目前,我使用Asp.net核心1.1,EF核心& Asp.net核心身份在我的系统。 我在startup.cs类的密码策略下面有一个配置。如何禁用帐户如果用户登录失败Asp.Net核心身份

当用户连续登录失败时,是否有配置禁用帐户?

services.Configure<IdentityOptions>(options => 
{ 
    // Password settings 
    options.Password.RequireDigit = true; 
    options.Password.RequiredLength = 6; 
    options.Password.RequireNonAlphanumeric = true; 
    options.Password.RequireUppercase = true; 
    options.Password.RequireLowercase = true; 
} 

回答

5

你可以简单地做这样的

options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(30); 
options.Lockout.MaxFailedAccessAttempts = 5; 
options.Lockout.AllowedForNewUsers = true; 

更多详情见this link

1

在您的帐户控制器,向下滚动到public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)

一旦出现,设置shouldLockouttrue

var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: true);