密碼強度檢測(Java)
阿新 • • 發佈:2019-01-02
不多說了,直接程式碼走你!!!
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; } }