|
@ -3,6 +3,7 @@ import java.security.SecureRandom; |
|
|
public class PasswordGenerator { |
|
|
public class PasswordGenerator { |
|
|
|
|
|
|
|
|
final String lowercaseCharacters = "abcdefghjkmnpqrstuvwxyz"; |
|
|
final String lowercaseCharacters = "abcdefghjkmnpqrstuvwxyz"; |
|
|
|
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
|
|
|
|
|
|
int length = 12; |
|
|
int length = 12; |
|
|
|
|
|
|
|
@ -17,9 +18,13 @@ public class PasswordGenerator { |
|
|
public String generateRandomPassword() { |
|
|
public String generateRandomPassword() { |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
SecureRandom rand = new SecureRandom(); |
|
|
SecureRandom rand = new SecureRandom(); |
|
|
|
|
|
String characterPool = ""; |
|
|
|
|
|
|
|
|
|
|
|
characterPool += lowercaseCharacters; |
|
|
|
|
|
characterPool += uppercaseCharacters; |
|
|
|
|
|
|
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
for (int generatorPosition = 0; generatorPosition < getLength(); generatorPosition++) { |
|
|
generatedPassword.append(lowercaseCharacters.charAt(rand.nextInt(lowercaseCharacters.length()))); |
|
|
|
|
|
|
|
|
generatedPassword.append(characterPool.charAt(rand.nextInt(characterPool.length()))); |
|
|
} |
|
|
} |
|
|
return generatedPassword.toString(); |
|
|
return generatedPassword.toString(); |
|
|
} |
|
|
} |
|
|