|
|
@ -5,11 +5,13 @@ public class PasswordGenerator { |
|
|
|
final String lowercaseCharacters = "abcdefghjkmnpqrstuvwxyz"; |
|
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
|
final String digits = "0123456789"; |
|
|
|
final String specialCharacters = ".!?=@#$()%^&/*_-+"; |
|
|
|
|
|
|
|
private int length = 12; |
|
|
|
private boolean useUppercase = true; |
|
|
|
private boolean useLowercase = true; |
|
|
|
private boolean useDigits = true; |
|
|
|
private boolean useSpecialCharacters = true; |
|
|
|
|
|
|
|
|
|
|
|
public String generateRandomPassword() { |
|
|
@ -26,6 +28,9 @@ public class PasswordGenerator { |
|
|
|
if (isUseDigits()) { |
|
|
|
characterPool += digits; |
|
|
|
} |
|
|
|
if (isUseSpecialCharacters()) { |
|
|
|
characterPool += specialCharacters; |
|
|
|
} |
|
|
|
|
|
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
|
generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); |
|
|
@ -57,6 +62,14 @@ public class PasswordGenerator { |
|
|
|
this.useDigits = useDigits; |
|
|
|
} |
|
|
|
|
|
|
|
public boolean isUseSpecialCharacters() { |
|
|
|
return useSpecialCharacters; |
|
|
|
} |
|
|
|
|
|
|
|
public void setUseSpecialCharacters(boolean useSpecialCharacters) { |
|
|
|
this.useSpecialCharacters = useSpecialCharacters; |
|
|
|
} |
|
|
|
|
|
|
|
public int getLength() { |
|
|
|
return length; |
|
|
|
} |
|
|
|