password generator

Hi

I am making a random pwd generator. should be min. 8 in length atleast 1 num, 1 special char, 1 UpperCase

to start out with i am doing something like this. (psudo)

String valid ="abcdefghijklmnopqrstuvwxyz";

String validUpper ="ABCDEFGHIJKLMNOPQRSTUVWXYZ";

String validNumber ="1234567890";

String validSpecial ="!@#$%^&*";

char valid1 [] =valid.toCharArray();

char validUpper1 [] = validUpper.toCharArray();

char validNumber1 [] = validNumber.toCharArray();

char validSpecial1 [] = validSpecial.toCharArray();

Random r = SecureRandom.getInstance("SHA1PRNG");

for (int i=1; i<4; i++ )

password += validChars[r.nextInt(validChars.length)];

for (int i = 1; i < 5; i++)

password += validUpper1[r.nextInt(validUpper1.length)];

password += validNumber1[r.nextInt(validNumber1.length)];

password += speicalNumber1[r.nextInt(speicalNumber1.length)];

that code i wrote..fulfills the requirements. but as you would notice..all lowercase chars are stacked together as a group and all uppderCase chars are stacked together. I'd like them to be random and kind of jumbled up rahter than in groups.

any good suggestions?

Message was edited by:

bhaarat_java

[1688 byte] By [bhaarat_javaa] at [2007-11-27 3:23:02]
# 1

Randomize the choosing of which one you want...

You have 4 groups to choose from so gen 0 to 3 and pic from that group. To assure you have at least 1 of each then gen 4 numbers to start between 0 and length-1 for mandatory palcement.

Once you have that, then just go randomly though each position until you come to the end, just be sure to pull from the required lists for the group selections you pre-generated.

morgalra at 2007-7-12 8:25:47 > top of Java-index,Java Essentials,Java Programming...
# 2

If you don't want it done that way, then don't do it that way. Do it the way you want it done:String valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

String validNumber = "1234567890";

String validSpecial = "!@#$%^&*";

char valid1 [] =valid.toCharArray();

char validNumber1 [] = validNumber.toCharArray();

char speicalNumber1 [] = validSpecial.toCharArray();

Random r = SecureRandom.getInstance("SHA1PRNG");

for (int i=1; i<8; i++ )

password += valid1[r.nextInt(valid1.length)];

password += validNumber1[r.nextInt(validNumber1.length)];

password += speicalNumber1[r.nextInt(speicalNumber1.length)];

DrClapa at 2007-7-12 8:25:47 > top of Java-index,Java Essentials,Java Programming...
# 3

You have a few options available and it all depends on how you feel like meeting the requirements. Instead of putting all lower and all upper case characters together make 1 array with all of the lower and upper case characters together then choose positions 1 to 7 from that list at random. As a final step check to insure that there is at least one lower case and at least one upper case character in that portion. If there isn't at least one of those, choose a character at random from that section and change the case from upper to lower or lower to upper.

patrickmallettea at 2007-7-12 8:25:47 > top of Java-index,Java Essentials,Java Programming...
# 4
Or take what the good doctor posted and modify that to insure all of your specifications are met for each password.
patrickmallettea at 2007-7-12 8:25:47 > top of Java-index,Java Essentials,Java Programming...
# 5

i made one array with everthing in it and then diffefernt arrays with my requirements. after the random pwd has been generated from array that has everything..i check every character's decimal val to determine if all 3 requirements have been satisfied. if not..i add the requrirement char somewhere in the string.

works good.

thanks every one.

Message was edited by:

bhaarat_java

bhaarat_javaa at 2007-7-12 8:25:47 > top of Java-index,Java Essentials,Java Programming...