How to customize password strength rules? #7182
-
I want to modify the default password strength rules. How should I modify it? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments
-
there is a class called PasswordStrengthValidator, and this is set up in Startup.cs:
... so you have to write your own class that implements the interface IPasswordStrengthValidator and substitute for the above line in Startup.cs to call your class. |
Beta Was this translation helpful? Give feedback.
-
@LSNicholls I'll try this, thanks for your reply! |
Beta Was this translation helpful? Give feedback.
-
@ronnylam1210 actually it may be easier than that, if all you want to do is make some changes according to the abilities of the default PasswordStrengthValidator class. Have a look at https://github.com/serenity-is/common-features/blob/master/src/Serenity.Extensions/Modules/Membership/MembershipSettings.cs. If you just need to tweak those settings, you just change appsettings.json and you're done, right? Sorry, I didn't think of that earlier! |
Beta Was this translation helpful? Give feedback.
-
@LSNicholls Yes, it seems that modifying MembershipSettings can achieve the function I want, but this is in Serenity.Extensions. How should I modify or create a new setting file to achieve customized rules? Thanks for your reply! |
Beta Was this translation helpful? Give feedback.
-
you don't have to create a new file. You just need to put a Membership section into appsettings.json, as I said. Right? for example:
... use the MembershipSettings.cs file to understand what you can put in that section. |
Beta Was this translation helpful? Give feedback.
-
When I put custom membership rules in appsettings, it worked! |
Beta Was this translation helpful? Give feedback.
-
@ronnylam1210 , yes. Thank you for providing the error information. It seems that your answer is right there. Did you comment out the line that sets up the default PasswordStrengthValidator in Startup.cs, in preparation for adding one of your own, and then forget to un-comment it when you settled on the approach that only needs you to put a Membership section in appsettings.json? |
Beta Was this translation helpful? Give feedback.
-
@LSNicholls The function can be used normally, thanks you for your help!! |
Beta Was this translation helpful? Give feedback.
you don't have to create a new file. You just need to put a Membership section into appsettings.json, as I said. Right? for example:
... use the MembershipSettings.cs file to understand what you can put in that section.