Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore password validation in IdentityDataSeeder. #7677

Closed
maliming opened this issue Feb 9, 2021 · 0 comments · Fixed by #7718
Closed

Ignore password validation in IdentityDataSeeder. #7677

maliming opened this issue Feb 9, 2021 · 0 comments · Fixed by #7718
Assignees
Labels
Milestone

Comments

@maliming
Copy link
Member

maliming commented Feb 9, 2021

IdentityOptions.Value.Password.ClearRequirements() only the default password verification rules will be ignored, and the custom IPasswordValidator can't be ignored.

public class MyPasswordValidator : IPasswordValidator<IdentityUser>
{
    public Task<IdentityResult> ValidateAsync(UserManager<IdentityUser> manager, IdentityUser user, string password)
    {
        if (password == user.UserName || password == user.Email)
        {
            return Task.FromResult(IdentityResult.Failed(new IdentityError
            {
                Description = "The password cannot be the same as the username or email."
            }));
        }

        return Task.FromResult(IdentityResult.Success);
    }
}

Create user without validate password. validatePassword: false

public virtual async Task<IdentityResult> CreateWithoutValidatePasswordAsync(IdentityUser user, string password)
{
    var result = await CreateAsync(user);
    if (!result.Succeeded)
    {
        return result;
    }

    return await UpdatePasswordHash(user, password, validatePassword: false);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants