1 private static String get_StrongPassword(int len) { 2 if (len < 6) 3 len = 6; 4 5 String digit = "0123456789"; 6 String alpha_lower = "abcdefghijklmnopqrstuvwxyz"; 7 String alpha_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 8 String symbl = " `~!@#$%^&*()-_=+\\|[{]};:'\",<.>/?"; 9 // String space = " \t"; 10 11 ArrayList<String[]> ary = new ArrayList<String[]>(); 12 ary.add(toCharStringArray(digit)); 13 ary.add(toCharStringArray(alpha_lower)); 14 ary.add(toCharStringArray(alpha_upper)); 15 ary.add(toCharStringArray(symbl)); 16 17 String[] pass = new String[len]; 18 String ss = ""; 19 20 // TODO get_StrongPassword : benchmark 21 for (int test = 0; test < 1000; test++) { 22 for (int i = 0; i < len; i++) { 23 24 String[] ae = ary.get((int) (Math.random() * 4)); 25 pass[i] = ae[(int) (Math.random() * ae.length)]; 26 } 27 ss = prtStrAry(pass, len); 28 } 29 30 return ss; 31 }
1 private static String[] toCharStringArray(String str) { 2 if (str == null) 3 return null; 4 5 ArrayList<String> chary = new ArrayList<String>(); 6 for (int i = 0; i < str.length(); i++) 7 chary.add(str.substring(i, i + 1)); 8 9 return chary.toArray(new String[0]); 10 }
标签:String,密码,int,ary,toCharStringArray,编程,len,留存,add From: https://www.cnblogs.com/jinzhenshui/p/18176953