您的位置:首页 > 编程语言 > Java开发

密码强度检测(Java)

2013-08-23 23:42 246 查看
不多说了,直接代码走你!!!

public class CheckPassword {

/**
* 密码强度
*
* @return Z = 字母 S = 数字 T = 特殊字符
*/
public String checkPassword(String passwordStr) {
String regexZ = "\\d*";
String regexS = "[a-zA-Z]+";
String regexT = "\\W+$";
String regexZT = "\\D*";
String regexST = "[\\d\\W]*";
String regexZS = "\\w*";
String regexZST = "[\\w\\W]*";

if (passwordStr.matches(regexZ)) {
return "弱";
}
if (passwordStr.matches(regexS)) {
return "弱";
}
if (passwordStr.matches(regexT)) {
return "弱";
}
if (passwordStr.matches(regexZT)) {
return "中";
}
if (passwordStr.matches(regexST)) {
return "中";
}
if (passwordStr.matches(regexZS)) {
return "中";
}
if (passwordStr.matches(regexZST)) {
return "强";
}
return passwordStr;

}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息