ASP.NET Identity Custom PasswordValidator to verify username

I want to add verification that the password does not contain the username in the ASP.NET ID environment.

Implementing a custom PasswordValidator should do the job fine, but how can I access the username?

public class CustomPasswordValidator : PasswordValidator { public override async Task<IdentityResult> ValidateAsync(string password) { var result = await base.ValidateAsync(password); //How to access username here return result; } } 
+5
source share
1 answer

You can take a look at the Free Validation Library

This has a predicate validator (required) that is perfect for your scenario. So your validation rule will look like this:

  RuleFor(model => model.Password) .Must((model, username) => !model.Password.Contains(username)) 
0
source

Source: https://habr.com/ru/post/1213716/


All Articles