|
@ -12,6 +12,7 @@ public class PasswordGenerator { |
|
|
private boolean useLowercase = true; |
|
|
private boolean useLowercase = true; |
|
|
private boolean useDigits = true; |
|
|
private boolean useDigits = true; |
|
|
private boolean useSpecialCharacters = true; |
|
|
private boolean useSpecialCharacters = true; |
|
|
|
|
|
private boolean requireEveryConfiguredCharacterType = true; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public String generateRandomPassword() { |
|
|
public String generateRandomPassword() { |
|
@ -33,7 +34,23 @@ public class PasswordGenerator { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); |
|
|
|
|
|
|
|
|
String customCharacterPool = characterPool; |
|
|
|
|
|
|
|
|
|
|
|
if (isRequireEveryConfiguredCharacterType()) { |
|
|
|
|
|
if (generatorPosition == 0 && isUseLowercase()) { |
|
|
|
|
|
customCharacterPool += lowercaseCharacters; |
|
|
|
|
|
} else if (generatorPosition == 1 && isUseUppercase()) { |
|
|
|
|
|
customCharacterPool += uppercaseCharacters; |
|
|
|
|
|
} else if (generatorPosition == 2 && isUseDigits()) { |
|
|
|
|
|
customCharacterPool += digits; |
|
|
|
|
|
} else if (generatorPosition == 3 && isUseSpecialCharacters()) { |
|
|
|
|
|
customCharacterPool += specialCharacters; |
|
|
|
|
|
} else { |
|
|
|
|
|
customCharacterPool = characterPool; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
generatedPassword.append(customCharacterPool.charAt(rand.nextInt(customCharacterPool.length()))); |
|
|
} |
|
|
} |
|
|
return generatedPassword.toString(); |
|
|
return generatedPassword.toString(); |
|
|
} |
|
|
} |
|
@ -70,6 +87,14 @@ public class PasswordGenerator { |
|
|
this.useSpecialCharacters = useSpecialCharacters; |
|
|
this.useSpecialCharacters = useSpecialCharacters; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isRequireEveryConfiguredCharacterType() { |
|
|
|
|
|
return requireEveryConfiguredCharacterType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void setRequireEveryConfiguredCharacterType(boolean requireEveryConfiguredCharacterType) { |
|
|
|
|
|
this.requireEveryConfiguredCharacterType = requireEveryConfiguredCharacterType; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public int getLength() { |
|
|
public int getLength() { |
|
|
return length; |
|
|
return length; |
|
|
} |
|
|
} |
|
|