Check if a password is valid using ASP.NET Identity 2
You can simply use PasswordValidator to check for password validity and errors as shown below:
var passwordValidator = new PasswordValidator<IdentityUser>();
var result = await passwordValidator.ValidateAsync(_userManager, null, "your password here");
if (result.Succeeded)
{
// Valid Password
}
else
{
// Check the error messages in result.Errors
}
Above solution works for Asp.Net Core 2.2
You may be able to use the PasswordValidator.ValidateAsync()
method to determine if a password meets the criteria defined in your UserManager
:
var valid = (await UserManager.PasswordValidator.ValidateAsync("pass")).Succeeded;