您的位置:首页 > 编程语言 > C#

C#正则表达式检测字符串(密码强度)

2009-08-05 15:25 302 查看
C# 判断是否英文或数字:

Regex reg = new Regex(@"^[A-Za-z0-9]+$");
return reg.IsMatch(passwd);


Javascript检测密码字符串强度:

int intScore = 0;
if (passwd.match(/[a-z]/))
{
intScore = (intScore+1)
} if (passwd.match(/[A-Z]/))
{
intScore = (intScore+5)
}
if (passwd.match(//d+/))
{
intScore = (intScore+5)
} if (passwd.match(/(/d.*/d.*/d)/))
{
intScore = (intScore+5)
}
if (passwd.match(/[!,@#$%^&*?_~]/))
{
intScore = (intScore+5)
} if (passwd.match(/([!,@#$%^&*?_~].*[!,@#$%^&*?_~])/))
{
intScore = (intScore+5)
}
if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/))
{
intScore = (intScore+2)
}
if (passwd.match(//d/) && passwd.match(//D/)) // [verified] both letters and numbers
{
intScore = (intScore+2)
}
if (passwd.match(/[a-z]/) && passwd.match(/[A-Z]/) && passwd.match(//d/) && passwd.match(/[!,@#$%^&*?_~]/))
{
intScore = (intScore+2)
}
return intScore;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: