locked
When Password is provided in non-English (that is Russian / Spanish / French) ASPNet Identity provider throws error RRS feed

  • Question

  • User-1233204413 posted

    I am working on an application which is going to support 10-15 different languages.

    Below is my ASPNet Identity providers password validation configuration 

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

    Based on above configuration user only has to provide a password which should have upper case, lower case , number and minimum length 7 character. 

    Now when a user provide a password as "Выбрать001Выбрать001" the Identity provided throws the error as "Passwords must have at least one lowercase ('a'-'z'). Passwords must have at least one uppercase ('A'-'Z')."

    I have spent couple of hours but can't able to get any clue. Any Valuable help is much appreciated.

    Thanks,

    Mahesh

    Monday, April 4, 2016 8:12 AM

Answers

  • User614698185 posted

    Hi maheshnair,

    Welcome to ASP.NET Forums!

    If you want to implement custom password policy using ASP.NET Identity, for example, passwords should have at least one special character and one numeral, like below:

    public class CustomPasswordValidator : IIdentityValidator<string>
    { 
      public int RequiredLength { get; set; }   
      public CustomPasswordValidator(int length)
      {  
        RequiredLength = length;
      }
      
      public Task<IdentityResult> ValidateAsync(string item)  
     { 
       if (String.IsNullOrEmpty(item) || item.Length < RequiredLength)  
       { 
          return Task.FromResult(IdentityResult.Failed(String.Format("Password should be of length {0}",RequiredLength)));  
       }
      
       string pattern = @"^(?=.*[0-9])(?=.*[!@#$%^&*])[0-9a-zA-Z!@#$%^&*0-9]{10,}$";
       if (!Regex.IsMatch(item, pattern))  
       {  
          return Task.FromResult(IdentityResult.Failed("Password should have one numeral and one special character"));  
       }
       
       return Task.FromResult(IdentityResult.Success);  
    }

    Please see: https://blogs.msdn.microsoft.com/webdev/2014/01/06/implementing-custom-password-policy-using-asp-net-identity/

    But as far as I know, it cannot use different languages in identity. If you change the different language password, it will lead to the result does not match the encryption password.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 5, 2016 3:04 AM

All replies

  • User614698185 posted

    Hi maheshnair,

    Welcome to ASP.NET Forums!

    If you want to implement custom password policy using ASP.NET Identity, for example, passwords should have at least one special character and one numeral, like below:

    public class CustomPasswordValidator : IIdentityValidator<string>
    { 
      public int RequiredLength { get; set; }   
      public CustomPasswordValidator(int length)
      {  
        RequiredLength = length;
      }
      
      public Task<IdentityResult> ValidateAsync(string item)  
     { 
       if (String.IsNullOrEmpty(item) || item.Length < RequiredLength)  
       { 
          return Task.FromResult(IdentityResult.Failed(String.Format("Password should be of length {0}",RequiredLength)));  
       }
      
       string pattern = @"^(?=.*[0-9])(?=.*[!@#$%^&*])[0-9a-zA-Z!@#$%^&*0-9]{10,}$";
       if (!Regex.IsMatch(item, pattern))  
       {  
          return Task.FromResult(IdentityResult.Failed("Password should have one numeral and one special character"));  
       }
       
       return Task.FromResult(IdentityResult.Success);  
    }

    Please see: https://blogs.msdn.microsoft.com/webdev/2014/01/06/implementing-custom-password-policy-using-asp-net-identity/

    But as far as I know, it cannot use different languages in identity. If you change the different language password, it will lead to the result does not match the encryption password.

    Best Regards,

    Candice Zhou

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 5, 2016 3:04 AM
  • User364663285 posted

    The error means either lower case or upper case English characters should be included to the password.

    Tuesday, April 5, 2016 5:08 AM