Implement dynamic Password Policy from database using RegularExpression Validator in ASP.Net

Last Reply on Jun 02, 2014 04:36 AM By Azim

Posted on Jun 02, 2014 04:12 AM

I had implemented Password Policy in which user should enter atleast 8 character of password with below complexity while setting password:

1 capital/Uppercase character , 1 special character and 1 number

I tried below code for above:

<asp:TextBox ID="passwordtxt" runat="server" Width="100%" TextMode="Password" MaxLength="10"></asp:TextBox>
<asp:RegularExpressionValidator ID="Regex1" runat="server" ControlToValidate="passwordtxt" ValidationExpression="^(?=.*[A-Z])(?=.*\d)(?=.*[$@$!%*#?&])[A-Za-z\d$@$!%*#?&]{8,}$" ErrorMessage="Password must contain: Minimum 8 characters with atleast 1 Uppercase letter, 1 special character and 1 Number" ForeColor="Red" />

by referring below article:

http://www.aspsnippets.com/Articles/Implement-Password-Policy-using-Regular-Expressions-and-ASPNet-RegularExpression-Validator.aspx

But in this code, I have to follow that:

while entering password if it is below 8 character, then msg should come "password should be atleast 8 characters"
and after entering password, when user tries to save password, and if password is missing any of the complexity i.e., 1 capital/Uppercase character , 1 special character and 1 number,

then msg should come "password should have 1 capital/Uppercase character , 1 special character and 1 number".

Also, this complexity feature should be configurable in Database table.
If enabled, then enter complex password
If disabled, then only 8 charatcter password with no cpmlexity

 

Please reply how to achieve that.

This question does not have replies that have been liked.