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