Skip to content

Instantly share code, notes, and snippets.

@phase
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save phase/022a8f246b237f54625d to your computer and use it in GitHub Desktop.

Select an option

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

phase commented Jan 23, 2015

Copy link
Copy Markdown
Author

Updated to fix the fourth comment.

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