Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Random Password Generation Tool?

 
Sloan Bowman
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 299
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Tony Xavier
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic