开发者

Password generation in Java [closed]

It's difficult to 开发者_JAVA百科tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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);
}

}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜