I am looking to create a simple application that creates random passwords for user accounts. For example you either runt the class or (if using swing) click a generate button and it creates a random password for you using the selected amount of characters. Is there an easy way to do this or does anybody have any suggestions?
Donny Nadolny
Ranch Hand
Joined: Mar 05, 2003
Posts: 32
posted
0
What you could do is create a string containing all the valid characters for a password, and use a loop to go for however many characters you want the password to be, and chose a random character from that string. If you need more clarification then just reply.
- Donny Nadolny<br />The pen is mightier than the sword, and considerably easier to write with.
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12267
1
posted
0
Consider leaving out the characters that people always get confused and are hard to distinquish in typical displays, such as the letters i and l and numeral 1 - also the letter O and numeral 0 from the pool of characters. Your users will thank you. Bill
Brian Pipa
Ranch Hand
Joined: Sep 29, 2003
Posts: 299
posted
0
Here is some code that does something similar. It creates a random 15 character username (which is essentially a password). You should be able to modify it to mkae it do what you want.
re leaving some out ... I leave out the vowels - avoids accidentally generating offensive words (enough monkeys, enough typewriters ...) and skips those I 1 O 0 problems. Another idea ... if you can find a free dictionary with a few thousand words, you could randomly select two or three words. Much easier to remember than a random string of letters & numbers. I still remember my first Compuserve password from 20 years ago was "water boldly".
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Tony Xavier
Greenhorn
Joined: Feb 07, 2004
Posts: 7
posted
0
To shorten your string of chars work you can use the ascii method to include all numbers, lower case letters and upper case letters. _________________________________________________________ char [] Chars = new char [63]; int counter = 0; for (int i = 48 ; i < 123 ; i++) { counter++; //ignore all other chars if (i == 58) i = 65; if (i == 91) i = 97; /* //remove the comments if you want remove all vowels //add and remove vowels as necessary char ch = (char) i; if (ch == 'a' || ch == 'e' || ch == 'o' || ch == 'u' || ch == 'i' || ch == 'y' || ch == 'A' || ch == 'E' || ch == 'O' || ch == 'U' || ch == 'I' || ch == 'Y') counter--; else */ Chars [counter] = (char) i;
} ________________________________________________________ Just something you might want to use for future as well. B.G