Google+ Followers

Nov 23, 2010

Generate random passwords

Here is a simple way with no effort to create random passwords like with the characters you want.
You will need this member:
private static final String charset = "aAbBcCdD$#eEf!=m2MnN3oOp4P8VwWx9XyY0zZ";
And this method:
public String getPasswordString(int length) {
Random randomSeed = new Random(System.currentTimeMillis());
StringBuilder result= new StringBuilder();
for (int i = 0; i < length; i++) {
int pos = randomSeed .nextInt(charset.length());
return result.toString();
Of course there is another way by using the UUID object:
Or maybe using an external third party library.
Hoped i helped,

No comments:

Post a Comment