Pages

Ads 468x60px

Sunday, July 22, 2012

Java: Simple Password Generator

This program can be used to generate a very simple and specific password according to requirements.



import java.util.Random;

public class PasswordGenerator {
 
    private Random rgen = new Random();

public static void main(String[] args){
System.out.println(new PasswordGenerator().generate());
}

public String generate(){

            StringBuilder sb = new StringBuilder();
            sb.append(rgen.nextInt(9));
            sb.append((char)(rgen.nextInt(25) + 65));
            sb.append((char)(rgen.nextInt(25) + 65));
            sb.append(rgen.nextInt(9));
            sb.append((char)(rgen.nextInt(25) + 65));
            sb.append((char)(rgen.nextInt(25) + 65));
            sb.append(rgen.nextInt(9));
            sb.append((char)(rgen.nextInt(25) + 65));
            sb.append((char)(rgen.nextInt(25) + 65));  
   return sb.toString();
}
}

No comments:

Post a Comment