/** * 是否有效密码 * @param pwd * @return */ public static boolean isValidPwd(String pwd) { int numasc = 0; int charasc = 0; int otherasc = 0; String v = pwd; if (0 == v.length()) { return false; } else if (v.length() < 8 || v.length() > 20) {// 长度判断 return false; } else { for (int i = 0; i < v.length(); i++) { int asciiNumber = v.charAt(i); if (asciiNumber >= 48 && asciiNumber <= 57) { numasc += 1; } if ((asciiNumber >= 65 && asciiNumber <= 90) || (asciiNumber >= 97 && asciiNumber <= 122)) { charasc += 1; } if ((asciiNumber >= 33 && asciiNumber <= 47) || (asciiNumber >= 58 && asciiNumber <= 64) || (asciiNumber >= 91 && asciiNumber <= 96) || (asciiNumber >= 123 && asciiNumber <= 126)) { otherasc += 1; } } if (0 == numasc) { //return "密码必须含有数字"; return false; } else if (0 == charasc) { //return "密码必须含有字母"; return false; } else if (0 == otherasc) { return false; // return "密码必须含有特殊字符"; } else { return true; } } }
检测密码是否有效,包含大写、小写、数字、特殊符号等
最新推荐文章于 2023-08-16 14:30:36 发布