Die Codekopie lautet wie folgt:
Paket com.phyl.password;
Import Java.util.ArrayList;
Import Java.util.Arrays;
import Java.util.random;
/**
* Zeichen zufällig erzeugte Klasse
* @Author Asus
*
*/
public class Passwort {
/**
* Aufzählungstyp -Aufzählung
* @Author Asus
*/
public static enum type {
/**
* Zeichentyp
*/
BRIEF,
/**
*Großbuchstaben -Charakter -Typ
*/
HAUPTSTADT,
/**
* Digitaler Typ
*/
NUMMER,
/**
* Symboltyp
*/
ZEICHEN,
/**
* Großer + kleiner Zeichentyp
*/
Letter_Capital,
/**
* Kleine Zeichen + numerisch
*/
Letter_Number,
/**
* Großer + kleiner Zeichen + Zahlentyp
*/
Letter_Capital_Number,
/**
* Große + kleine Zeichen + Zahlen + Symbolisch
*/
Letter_Capital_Number_sign
}
private statische Zeichenfolge [] Kleinbuchstaben = {
"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 statische 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 statische String [] number = {
"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"};
private statische String [] Sign = {
"~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+ "," "", "-", "=",
"{", "}", "|", ":", "/" "," <","> ","? ",
"[", "]", "//", ";", "'", ",", ",", ".", ",/"};
/**
* Statische Zufallszahl
*/
private static random random = new random ();
public static void main (String [] args) {
System.out.println (password.getRandom (24, password.type.capital));
}
/**
* Erhalten Sie zufällige Kombinationscodes
* @param num Anzahl der Ziffern
* @param type
* @Typ
* <br> Zeichenbrief,
* <br> Kapital,
* <br> Nummer,
* <br> Symbolzeichen,
* <br> Letter_Capital,
* <br> Kleine Zeichen + numerischer Buchstaben_Number,
* <br> Große + kleine Zeichen + numerische Buchstabe_Capital_Number,
* <br> Große + kleine Zeichen + Zahlen + symbolische Buchstabe_Capital_Number_sign
*/
public static String getRandom (int num, Typtyp) {
ArrayList <string> temp = new ArrayList <string> ();
StringBuffer code = new StringBuffer ();
if (type == type.letter) {
temp.addall (arrays.aslist (Kleinbuchstaben));
} else if (type == type.capital) {
temp.addall (arrays.aslist (Kapital));
} else if (type == type.number) {
temp.addall (arrays.aslist (number));
} else if (type == type.Sign) {
temp.addall (arrays.aslist (Zeichen));
} else if (type == type.letter_capital) {
temp.addall (arrays.aslist (Kleinbuchstaben));
temp.addall (arrays.aslist (Kapital));
} else if (type == type.letter_number) {
temp.addall (arrays.aslist (Kleinbuchstaben));
temp.addall (arrays.aslist (number));
} else if (type == type.letter_capital_number) {
temp.addall (arrays.aslist (Kleinbuchstaben));
temp.addall (arrays.aslist (Kapital));
temp.addall (arrays.aslist (number));
} else if (type == type.letter_capital_number_sign) {
temp.addall (arrays.aslist (Kleinbuchstaben));
temp.addall (arrays.aslist (Kapital));
temp.addall (arrays.aslist (number));
temp.addall (arrays.aslist (Zeichen));
}
für (int i = 0; i <num; i ++) {
code.Append (temp.get (random.nextint (temp.size ()));
}
return code.toString ();
}
}