ASP.NET身份更改密码帐户锁定不起作用



我正在使用asp.net身份。在ChangePasswordAsync函数中,一个无效的旧密码不会触发帐户锁定,无论如何是否可以实现这一目标?通过笔测试将其作为低问题提出。

问候

Mike

您可以通过调用锁定功能来执行此操作,如果用户提供了错误的旧密码

int userId = User.Identity.GetUserId();
IdentityResult result = await UserManager.ChangePasswordAsync(userId , model.OldPassword, model.NewPassword);
if (result.Succeeded)
{
    userManager.ResetAccessFailedCount(userId);
}
else
{
    //you can add logic if the call didn't succeeded because of incorrect old 
    password and then execute the following line
    userManager.AccessFailed(userId);
}

最新更新