Created
December 6, 2018 11:55
-
-
Save ghsatpute/462d92a8dc848240cc495a789bf6705f to your computer and use it in GitHub Desktop.
Generate random password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RandomPassword { | |
private static String generateRandomPassword() { | |
Random random = new Random(); | |
char start = characters.charAt(Math.floorMod(random.nextInt(), characters.length())); | |
List<Character> chars = new ArrayList<>(); | |
for (int i = 0; i < 5; i++) { | |
chars.add(characters.charAt(Math.floorMod(random.nextInt(), characters.length()))); | |
} | |
chars.add(numeric.charAt(Math.floorMod(random.nextInt(), numeric.length()))); | |
chars.add(specialCharacters.charAt(Math.floorMod(random.nextInt(), specialCharacters.length()))); | |
Collections.shuffle(chars); | |
String lastChars = StringUtils.join(chars, ""); | |
return start + lastChars; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment