Tuesday, August 10, 2010

How to validate password strength using regular expression

Please note: code being formatted for the demonstration purposes.
<asp:TextBox runat="server" ID="txtMediumPassword" />
        <asp:RegularExpressionValidator runat="server" 
            ErrorMessage="Password should contain minimum 7 non repetitive characters" 
            ControlToValidate="txtMediumPassword" 
            ID="RegularExpressionValidator1" 
            ValidationExpression="^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$" />
<asp:TextBox runat="server" ID="txtStrongPassword" />
<asp:RegularExpressionValidator runat="server" 
    ErrorMessage="
        Password should contain minimum 8 non repetitive characters, 
        at least 1 Uppercase character, at least 1 lowercase character and at least 1 digit." 
    ControlToValidate="txtStrongPassword"
    ID="regexPassword" 
    ValidationExpression="^(?=.{8,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9])))(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9]).*$" />

No comments:

Azure Storage Account Types

Defferent Types of Blobs Block blobs store text and binary data. Block blobs are made up of blocks of data that can be managed individually...