'Net core Identity lockout not lockout user account
I try to enable lockout feature but I am not successed. Each time, I check database, AccessFailedCount is increase to 1 but after that again it turn to 0. What's wrong?
My codes are:
//Login page code
public async Task<IActionResult> OnPostAsync(string returnUrl = null) {
returnUrl = returnUrl ?? Url.Content("~/");
if (ModelState.IsValid) {
var result = await _signInManager.PasswordSignInAsync(Input.UserName, Input.Password, Input.RememberMe, lockoutOnFailure: true);
if (result.Succeeded) {
_logger.LogInformation("User logged in.");
return LocalRedirect(returnUrl);
}
if (result.RequiresTwoFactor) {
return RedirectToPage("./LoginWith2fa", new { ReturnUrl = returnUrl, RememberMe = Input.RememberMe });
}
if (result.IsLockedOut) {
_logger.LogWarning("User account locked out.");
return RedirectToPage("./Lockout");
}
else {
ModelState.AddModelError(string.Empty, "Invalid login attempt.");
return Page();
}
}
// If we got this far, something failed, redisplay form
return Page();
}
//services code
// Lockout settings.
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(5);
options.Lockout.MaxFailedAccessAttempts = 2;
options.Lockout.AllowedForNewUsers = true;
Solution 1:[1]
Make sure the User's LockoutEnabled
column is set to true
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | CSharper |