The input given for generating the password is combined with the current system
time and the random number generator is initialized.
The random number is got from the random number generator and the no. of random numbers depends on the password length given.
The character array with alpha numeric is initialized and the random number generated will be used as the index to get the characters from the array which frames the password.
The random number is got from the random number generator and the no. of random numbers depends on the password length given.
The character array with alpha numeric is initialized and the random number generated will be used as the index to get the characters from the array which frames the password.
import java.util.*; public class passwdgeneration { private static java.util.Random rd = new java.util.Random(); private static char charBase[] = {'A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9'}; public static void main(String args[]) { String str = args[0]; int inPassLength = Integer.parseInt(args[1]); byte[] buffer = new byte[inPassLength]; int curCount = 0; long testTmp=(System.currentTimeMillis()+str.hashCode()); rd.setSeed(testTmp); for( int count = 0; curCount<inPassLength; ++count) { int thisRandom = rd.nextInt(31); buffer[curCount++]=(byte)charBase[thisRandom]; } String stPass = new String(buffer); System.out.println("Password "+stPass); } }