Last active
August 29, 2015 14:14
-
-
Save phase/022a8f246b237f54625d to your computer and use it in GitHub Desktop.
Instead of random number generation, use this. It's a LITTLE more secure.
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
//Make static if going to be used static, but you might want to put the Random instance outside the class | |
public String generatePassword(int characterLimit){ | |
Random r = new Random(); //New Random instance | |
String u = UUID.randomUUID().toString().replaceAll("-", ""); //Get random Base64 string from a random UUID | |
return u.substring(0, r.getNetInt(characterLimit-3)+3); //Returns a substring of the UUID | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to fix the fourth comment.