标签:except param bsp int turn row getch length exce
public static void main(String[] args) throws Exception { String str = "WERUIuy%^*&5467"; int i = checkStrong(str); if(i<=2){ System.out.println("密码强度不够!"); } } /** * 计算出当前密码当中一共有多少种模式 * @param pwd * @return */ public static int checkStrong(String pwd){ if(pwd.length() < 4) return 0; int modes = 0; for(int i = 0;i<pwd.length();i++){ modes |= getCharMode(pwd.charAt(i)); //或 } return bitTotal(modes); } /** * 返回当前字符的模式 * @param i * @return */ public static int getCharMode(int i){ if (i >= 48 && i <= 57) //数字 return 1; if (i >= 65 && i <= 90) //大写字母 return 2; if (i >= 97 && i <= 122) //小写 return 4; else return 8; //特殊字符 } /** * 遍历数的二进制表示,看有多少个1 * @param num * @return */ public static int bitTotal(int num){ int modes = 0; for (int i = 0; i < 4; i++) { if ((num & 1) == 1) modes++; num >>>= 1; } return modes; }
标签:except param bsp int turn row getch length exce
原文地址:http://www.cnblogs.com/janetshen/p/6892566.html