Skip to content

Instantly share code, notes, and snippets.

@phase
Last active August 29, 2015 14:14
Show Gist options
  • Save phase/022a8f246b237f54625d to your computer and use it in GitHub Desktop.
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.
//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
}
@phase
Copy link
Author

phase commented Jan 23, 2015

Updated to fix the fourth comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment