aspose file tools
The moose likes Java in General and the fly likes random password generation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "random password generation" Watch "random password generation" New topic
Author

random password generation

Amit Babu
Greenhorn

Joined: Dec 09, 2005
Posts: 9
What sort of algorithm can be used for random password generation? I do not want a very complex algorithm. A simple but effective approach would be highly appreciated.
[ December 13, 2005: Message edited by: Amit Babu ]
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12928
    
    3

Simply create a java.util.Random object and write a loop to have it generate some random numbers (integers), and cast them to characters. For example:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12269
    
    1
Since certain character pairs are hard to distinguish in many fonts, you might consider discarding upper case i and l (I l) upper case o and zero (O 0 ) etc.
Those of us with aging vision will thank you.
Bill
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I select random characters from an array:

characters = "bcdfghjklmnpqrstvwxz23456789" ... get Byte Array ...

I leave out I O and 1 0 to avoid confusion as suggested above, and all vowels to avoid offensive words in any language except Qwlghm.

Any time this random password question comes up, I drag up CompuServe, the great online giant of the 80s and 2400 baud modems. Their passwords were two randomly chosen dictionary words. Mine was "water boldly". It's certainly easier to remember (for the last 25 years) than a random string of letters and digits.


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
Amit Babu
Greenhorn

Joined: Dec 09, 2005
Posts: 9
Originally posted by Jesper de Jong:
Simply create a java.util.Random object and write a loop to have it generate some random numbers (integers), and cast them to characters. For example:


This is eaxctly what I had in mind.
Glad to know that this could be a good algorithm.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: random password generation
 
Similar Threads
Pseudo Random Function for J2ME
Unique Random Number
i need help in random key generation algorithm and source code in java
Suggestion needed on digesting passwords
Random string generation