aspose file tools*
The moose likes Java in General and the fly likes Random Password Generation Tool? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Random Password Generation Tool?" Watch "Random Password Generation Tool?" New topic
Author

Random Password Generation Tool?

Sloan Bowman
Ranch Hand

Joined: Jan 21, 2003
Posts: 107
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
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: 12675
    
    5
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
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.

Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
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
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


"We all are unique, just like everybody else"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Random Password Generation Tool?
 
Similar Threads
Which crypto library should I use?
I Messed Up With My Thread Code
Java Assignment
bad padding exception
Suggestion needed on digesting passwords