Password generation in Java [closed]
I want a password generator in Java using JAR file, which should meet standard password rules. It would be great if it was open source. Any suggestions?
Thanks
less than a month ago, someone asked the same thing: Password generator in Java
this one is also very similar: How can I create a password?
this one too: Need a secure password generator recommendation
Some previous research is always good
Try this : JPWGEN
http://hillert.blogspot.com/2008/09/jpwgen-password-generator-for-java.html
private static final String charset = "0123456789abcdefghijklmnopqrstuvwxyz";
public static String getRandomPassword(int length) {
Random rand = new Random(System.currentTimeMillis());
StringBuilder sb = new StringBuilder();
for (int i = 0; i < length; i++) {
int pos = rand.nextInt(charset.length());
sb.append(charset.charAt(pos));
}
return sb.toString();
}
Take a lool at Md5PasswordEncoder
and PasswordEncoder
of acegi-security. And use it like:
public class SomeClass {
private PasswordEncoder passwordEncoder;
// other code
public String generatePassword() {
byte[] ab = new byte[1];
Random r = new Random();
r.nextBytes(ab);
return passwordEncoder.encodePassword(new String(ab), null).substring(24);
}
}
精彩评论