• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Random Password Generation Tool?

 
Ranch Hand
Posts: 107
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 299
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic