Monday, 10 September 2012

JAVA CODE TO GENERATE RANDOM PASSWORD

Posted by Unknown On 05:31 | No comments
public class PasswordGenerator {

static final String AB = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
    static Random rnd = new Random();

    public String randomString(int len)
    {
          StringBuilder sb = new StringBuilder(len);
           for( int i = 0; i < len; i++ )
                  sb.append( AB.charAt( rnd.nextInt(AB.length()) ) );
                System.out.println(sb);
           return sb.toString();
    }
    public static void main(String a[]){
        PasswordGenerator obj=new PasswordGenerator();
         String s=obj.randomString(6);
        System.out.println(s);
    }

0 comments:

Post a Comment

Blogroll

Blogger templates

About