locked
Add extra rules in Password complexity in asp.net mvc 5 RRS feed

  • Question

  • User-1710838230 posted

    Hi,

    As in below code, password rules defined. I need to add more rules. How can i add more rules in this build in functionality. I need extra rules else defined below. 

    manager.PasswordValidator = new PasswordValidator
    {
        RequiredLength = 6,
        RequireNonLetterOrDigit = true,
        RequireDigit = true,
        RequireLowercase = true,
        RequireUppercase = true,
    };
    Saturday, April 27, 2019 6:23 AM

All replies

  • User611346789 posted

    Hi,

    Try the below link. Hope that will be help you

    https://www.c-sharpcorner.com/uploadfile/4b0136/how-to-customize-password-policy-in-asp-net-identity/

    Sunday, April 28, 2019 4:18 PM
  • User1520731567 posted

    Hi FarhatKhan,

    First you can create a separate class CustomPasswordValidator which is inherited from IIdentityValidator<string>.

    You can then implement validation logic in ValidateAsync(T) method.

    There you will retrieve rules from DB and check them against the passed string argument.

    Then I suppose you are using a kind of ApplicationUserManager class derived from UserManager.

    Add a constructor parameter of IIdentityValidator<string> type to ApplicationUserManager, assign it to PasswordValidator property.

    ApplicationUserManager instance created with CustomPasswordValidator instance as an argument will validate you passwords against DB rules.

    Refer to this source of UserManager to see when exactly PasswordValidator property is called.

    You could also refer to this link:

    https://devblogs.microsoft.com/aspnet/implementing-custom-password-policy-using-asp-net-identity/

    Best Regards.

    Yuki Tao

    Monday, April 29, 2019 6:08 AM