
本站地址:http://www.bajiao123.com

/*用于生成对密码要求比较高的场合*/
import java.util.Random;
public class PasswordCreator {
private static final char[] sChars = { '!', '@', '#', '$', '%', '^', '&',
'*', '(', ')', '+', '-', '+', '_', '=', '<', '>', '?', ';', ':' };
private static final char[] aChars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z' };
private static final char[] AChars = { 'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z' };
private static final char[] nChars = { '0', '1', '2', '3', '4', '5', '6',
'7', '8', '9' };
private static final Random RANDOM = new Random();
private static final int MIN = 7;
private static final int MAX = 11;
/**
* @param args
*/
public static void main(String[] args) {
int minlength = MIN;
int maxlength = MAX;
try {
minlength = Integer.parseInt(args[0]);
maxlength = Integer.parseInt(args[1]);
} catch (Exception e) {
System.err.println("默认最大长度为10,最短长度为7,如果需要调整请输入:"
+ " PasswordCreator 最短长度值 最长长度值+1");
}
String result = createPassword(minlength, maxlength);
System.out.println("以下是否是您需要的PassWord:");
System.out.println(result);
}
public static String createPassword(int minLength, int maxLength) {
String sStr = random(maxLength, sChars);
String aStr = random(maxLength, aChars);
String AStr = random(maxLength, AChars);
String nStr = random(maxLength, nChars);
String str = sStr + aStr + AStr + nStr;
char[] lastChar = str.toCharArray();
str = random(maxLength - 1, lastChar);
// 最后密码的长度
int length = minLength
+ (int) (Math.random() * (maxLength - minLength));
str = str.substring(maxLength - length);
if (str.charAt(0) == '(') {
str = str.substring(1);
str = aChars[(int) (Math.random() * aChars.length)] + str;
}
str = str + sChars[(int) (Math.random() * sChars.length)];
return str;
}
public static String random(int count, String set) {
/* 243 */return random(count, set.toCharArray());
}
public static String random(int count, char set[]) {
/* 256 */return random(count, 0, set.length - 1, false, false, set);
}
public static String random(int count, int start, int end, boolean letters,
boolean numbers, char set[]) {
/* 200 */if (start == 0 && end == 0) {
/* 201 */end = 122;
/* 202 */start = 32;
/* 203 */if (!letters && !numbers) {
/* 204 */start = 0;
/* 205 */end = 2147483647;
}
}
/* 209 */StringBuffer buffer = new StringBuffer();
/* 210 */int gap = end - start;
/* 214 */while (count-- != 0) {
char ch;
/* 214 */if (set == null)
/* 215 */ch = (char) (RANDOM.nextInt(gap) + start);
/* 217 */else
/* 217 */ch = set[RANDOM.nextInt(gap) + start];
/* 219 */if (letters && numbers && Character.isLetterOrDigit(ch)
|| letters && Character.isLetter(ch) || numbers
&& Character.isDigit(ch) || !letters && !numbers)
/* 225 */buffer.append(ch);
/* 227 */els
本站地址:http://www.bajiao123.com

