|
@ -6,6 +6,7 @@ public class PasswordGenerator { |
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
final String uppercaseCharacters = "ABCDEFGHJKMNPQRSTUVWXYZ"; |
|
|
final String digits = "0123456789"; |
|
|
final String digits = "0123456789"; |
|
|
final String specialCharacters = ".!?=@#$()%^&/*_-+"; |
|
|
final String specialCharacters = ".!?=@#$()%^&/*_-+"; |
|
|
|
|
|
final SecureRandom rand = new SecureRandom(); |
|
|
|
|
|
|
|
|
private int length = 12; |
|
|
private int length = 12; |
|
|
private boolean useUppercase = true; |
|
|
private boolean useUppercase = true; |
|
@ -17,7 +18,6 @@ public class PasswordGenerator { |
|
|
|
|
|
|
|
|
public String generateRandomPassword() { |
|
|
public String generateRandomPassword() { |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
StringBuilder generatedPassword = new StringBuilder(); |
|
|
SecureRandom rand = new SecureRandom(); |
|
|
|
|
|
String characterPool = ""; |
|
|
String characterPool = ""; |
|
|
|
|
|
|
|
|
if (isUseLowercase()) { |
|
|
if (isUseLowercase()) { |
|
@ -55,6 +55,19 @@ public class PasswordGenerator { |
|
|
return generatedPassword.toString(); |
|
|
return generatedPassword.toString(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public String shufflePassword(String password) { |
|
|
|
|
|
StringBuilder shuffledPassword = new StringBuilder(); |
|
|
|
|
|
StringBuilder passwordCopy = new StringBuilder(password); |
|
|
|
|
|
|
|
|
|
|
|
while (passwordCopy.length() != 0) { |
|
|
|
|
|
int index = rand.nextInt(passwordCopy.length()); |
|
|
|
|
|
char c = passwordCopy.charAt(index); |
|
|
|
|
|
shuffledPassword.append(c); |
|
|
|
|
|
passwordCopy.deleteCharAt(index); |
|
|
|
|
|
} |
|
|
|
|
|
return shuffledPassword.toString(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
public boolean isUseUppercase() { |
|
|
public boolean isUseUppercase() { |
|
|
return useUppercase; |
|
|
return useUppercase; |
|
|
} |
|
|
} |
|
|