Friday 27 September 2013

Strong Password with regular expression in asp.net c#

Atleast 1-lower,1-upper,1-numeric,1-special character

public static string checkpasswordCharacters(string password)
    {
        string msg = "";      
        Regex len = new Regex("^.{6,15}$");
        Regex num = new Regex("\\d");
       // Regex alphaL = new Regex("\\D");
        Regex alphaL = new Regex("[a-z]");
        Regex alphaU = new Regex("[A-Z]");
        Regex special = new Regex("[><#@=._!$-]");

        if (!len.IsMatch(password) )
        {
            msg += "-Minimum password length is 6 characters \\n";
        }
        if (!num.IsMatch(password))
        {
            msg += "-Please enter atleast one numeric value \\n";
        }
        if (!alphaL.IsMatch(password))
        {
            msg += "-Please enter atleast one lower case alphabet \\n";
        }
        if (!alphaU.IsMatch(password))
        {
            msg += "-Please enter atleast one upper case alphabet \\n";
        }
        if (!special.IsMatch(password))
        {
            msg += "-Please enter atleast one special Character \\n";
        }
       
        return msg;      

    }

No comments:

Post a Comment

Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...