RequireNonLetterOrDigit incorrectly checked

I created a password validator as follows:

manager.PasswordValidator = new PasswordValidator { RequiredLength = 8, RequireNonLetterOrDigit = false, RequireDigit = false, RequireLowercase = true, RequireUppercase = true, }; 

But a password such as Testing123 is considered invalid:

Passwords must have at least one character without a letter or number.

The error message is rather unclear, it says that the password must contain at least one character without a letter or number. Well, I have 3 digits. So what is wrong then? When I add no letter

+5
source share
2 answers

Both the name and the documentation for this property are ambiguous. It should be:

Gets or sets whether a password is required for a character that is not a letter, not a number.

+10
source
  public class CustomPasswordValidator : PasswordValidator { public override async Task<IdentityResult> ValidateAsync(string password) { var requireNonLetterOrDigit = base.RequireNonLetterOrDigit; base.RequireNonLetterOrDigit = false; var result = await base.ValidateAsync(password); if (!requireNonLetterOrDigit) return result; if (!Enumerable.All<char>((IEnumerable<char>)password, new Func<char, bool>(this.IsLetterOrDigit))) return result; // Build a new list of errors so that the custom 'PasswordRequireNonLetterOrDigit' could be added. List<string> list = new List<string>(); foreach (var error in result.Errors) { list.Add(error); } // Add our own message: (The default by MS is: 'Passwords must have at least one non letter or digit character.') list.Add("Passwords must have at least one character that is neither a letter or digit. (Eg '£ $ % ^ _ etc.')"); result = await Task.FromResult<IdentityResult>(IdentityResult.Failed(string.Join(" ", (IEnumerable<string>)list))); return result; } } 
+1
source

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


All Articles