public static bool CheckPasswordStrength(string pwd)
{
var reExprDigit = new Regex("(?=.*[0-9])");
var reExprLowerCase = new Regex("(?=.*[a-z])");
var reExprUpperCase = new Regex("(?=.*[A-Z])");
var reExprSpecialChar = new Regex("(?=.*[@#$%/!^&*()+|??<>,~`=;:{}-])");
var reExprInputLen = new Regex("^.{6,18}$");
var count = 0;
var notfound = 0;
var pwdLen = 0;
//Search weather digits exists in input. If match found the validate it with digit RE.
if (reExprDigit.IsMatch(pwd))
{
if (reExprDigit.IsMatch(pwd))
{
//alert('reExprDigit');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather lower case exists in input. If match found the validate it with lower case RE.
if (reExprLowerCase.IsMatch(pwd))
{
if (reExprLowerCase.IsMatch(pwd))
{
//alert('reExprLowerCase');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather upper case exists in input. If match found the validate it with upper case RE.
if (reExprUpperCase.IsMatch(pwd))
{
if (reExprUpperCase.IsMatch(pwd))
{
//alert('reExprUpperCase');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather special char exists in input. If match found the validate it with special char RE.
if (reExprSpecialChar.IsMatch(pwd))
{
//alert('match found');
if (reExprSpecialChar.IsMatch(pwd))
{
//alert('reExprSpecialChar');
count++;
}
}
else
{
count++;
notfound++;
}
//alert(notfound);
if (reExprInputLen.IsMatch(pwd))
{
//alert('reExprInputLen');
pwdLen++;
}
if (count >= 4 && notfound < 2 && pwdLen > 0)
{
return true;
}
else
{
return false;
}
}
{
var reExprDigit = new Regex("(?=.*[0-9])");
var reExprLowerCase = new Regex("(?=.*[a-z])");
var reExprUpperCase = new Regex("(?=.*[A-Z])");
var reExprSpecialChar = new Regex("(?=.*[@#$%/!^&*()+|??<>,~`=;:{}-])");
var reExprInputLen = new Regex("^.{6,18}$");
var count = 0;
var notfound = 0;
var pwdLen = 0;
//Search weather digits exists in input. If match found the validate it with digit RE.
if (reExprDigit.IsMatch(pwd))
{
if (reExprDigit.IsMatch(pwd))
{
//alert('reExprDigit');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather lower case exists in input. If match found the validate it with lower case RE.
if (reExprLowerCase.IsMatch(pwd))
{
if (reExprLowerCase.IsMatch(pwd))
{
//alert('reExprLowerCase');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather upper case exists in input. If match found the validate it with upper case RE.
if (reExprUpperCase.IsMatch(pwd))
{
if (reExprUpperCase.IsMatch(pwd))
{
//alert('reExprUpperCase');
count++;
}
}
else
{
count++;
notfound++;
}
//Search weather special char exists in input. If match found the validate it with special char RE.
if (reExprSpecialChar.IsMatch(pwd))
{
//alert('match found');
if (reExprSpecialChar.IsMatch(pwd))
{
//alert('reExprSpecialChar');
count++;
}
}
else
{
count++;
notfound++;
}
//alert(notfound);
if (reExprInputLen.IsMatch(pwd))
{
//alert('reExprInputLen');
pwdLen++;
}
if (count >= 4 && notfound < 2 && pwdLen > 0)
{
return true;
}
else
{
return false;
}
}
No comments:
Post a Comment