Package Com.phyl.password;
Import java.util.ArrayList;
Import Java.util.Arrays;
Import Java.util.Random;
/**
* Character Random Generation class
* @author ASUS
*
*/
public class PassWord {
/**
* Password Type Enumeration
* @author ASUS
*/
public static enum TYPE {
/**
* Character type
*/
Letter,
/**
* Uppercase Character type
*/
Capital,
/**
* Digital Type
*/
Number,
/**
* Symbol type
*/
SIGN,
/**
* Large + small character type
*/
Letter_capital,
/**
* Small character + digital type
*/
Letter_number,
/**
* Large + small character + digital type
*/
Letter_capital_number,
/**
* Large + small character + digital + symbol type
*/
Letter_capital_number_sign
}
private static string[] lowercase = {
"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 string[] Capital = {
"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 string[] Number = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
private static string[] Sign = {
"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "'", "-", "=",
"{", "}", "|", ":", "\" "," < "," > ","? ",
"[","]","\\",";","'",",",".","/"};
/**
* Static random number
*/
private static Random Random = new Random ();
public static void Main (string[] args) {
System.out.println (Password.getrandom, PassWord.TYPE.CAPITAL));
}
/**
* Get random combination code
* @param num Digits
* @param type
* @type
* <br> Letter of character,
* <br> uppercase character type capital,
* <br> Number Type,
* <br> symbol Type SIGN,
* <br> large + small character type letter_capital,
* <br> Small character + digital type Letter_number,
* <br> Large + small character + digital type Letter_capital_number,
* <br> Large + small character + digital + symbol type Letter_capital_number_sign
*/
public static String getrandom (int num,type TYPE) {
arraylist<string> temp = new arraylist<string> ();
StringBuffer code = new StringBuffer ();
if (type = = Type. Letter) {
Temp.addall (arrays.aslist (lowercase));
}else if (type = = Type. Capital) {
Temp.addall (arrays.aslist (capital));
}else if (type = = Type. Number) {
Temp.addall (arrays.aslist (number));
}else if (type = = Type. SIGN) {
Temp.addall (Arrays.aslist (sign));
}else if (type = = Type. Letter_capital) {
Temp.addall (arrays.aslist (lowercase));
Temp.addall (arrays.aslist (capital));
}else if (type = = Type. Letter_number) {
Temp.addall (arrays.aslist (lowercase));
Temp.addall (arrays.aslist (number));
}else if (type = = Type. Letter_capital_number) {
Temp.addall (arrays.aslist (lowercase));
Temp.addall (arrays.aslist (capital));
Temp.addall (arrays.aslist (number));
}else if (type = = Type. Letter_capital_number_sign) {
Temp.addall (arrays.aslist (lowercase));
Temp.addall (arrays.aslist (capital));
Temp.addall (arrays.aslist (number));
Temp.addall (Arrays.aslist (sign));
}
for (int i = 0; i < num; i++) {
Code.append (Temp.get (Random.nextint (Temp.size ()));
}
return code.tostring ();
}
}