|
@ -6,28 +6,62 @@ public class PasswordGenerator { |
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
final String digits = "0123456789"; |
|
|
final String digits = "0123456789"; |
|
|
|
|
|
|
|
|
int length = 12; |
|
|
|
|
|
|
|
|
private int length = 12; |
|
|
|
|
|
private boolean useUppercase = true; |
|
|
|
|
|
private boolean useLowercase = true; |
|
|
|
|
|
private boolean useDigits = true; |
|
|
|
|
|
|
|
|
public int getLength() { |
|
|
|
|
|
return length; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setLength(int length) { |
|
|
|
|
|
this.length = length; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String generateRandomPassword() { |
|
|
public String generateRandomPassword() { |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
SecureRandom rand = new SecureRandom(); |
|
|
SecureRandom rand = new SecureRandom(); |
|
|
String characterPool = ""; |
|
|
String characterPool = ""; |
|
|
|
|
|
|
|
|
|
|
|
if (isUseLowercase()) { |
|
|
characterPool += lowercaseCharacters; |
|
|
characterPool += lowercaseCharacters; |
|
|
|
|
|
} |
|
|
|
|
|
if (isUseUppercase()) { |
|
|
characterPool += uppercaseCharacters; |
|
|
characterPool += uppercaseCharacters; |
|
|
|
|
|
} |
|
|
|
|
|
if (isUseDigits()) { |
|
|
characterPool += digits; |
|
|
characterPool += digits; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); |
|
|
generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); |
|
|
} |
|
|
} |
|
|
return generatedPassword.toString(); |
|
|
return generatedPassword.toString(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isUseUppercase() { |
|
|
|
|
|
return useUppercase; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setUseUppercase(boolean useUppercase) { |
|
|
|
|
|
this.useUppercase = useUppercase; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isUseLowercase() { |
|
|
|
|
|
return useLowercase; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setUseLowercase(boolean useLowercase) { |
|
|
|
|
|
this.useLowercase = useLowercase; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isUseDigits() { |
|
|
|
|
|
return useDigits; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setUseDigits(boolean useDigits) { |
|
|
|
|
|
this.useDigits = useDigits; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getLength() { |
|
|
|
|
|
return length; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setLength(int length) { |
|
|
|
|
|
this.length = length; |
|
|
|
|
|
} |
|
|
} |
|
|
} |