I know you've had answers already but I've been down this road, MOST people
don't cut and paste so to save yourself hassle of many support emails saying
"my password doesn't work" you would do well to limit the characters that
are used because people don't read stuff and a lot can't tell the difference
between lowercase 'l' and 'i' etc... this is worse if people use a 'groovy'
font in their email reader. So anyway I use this code below which eliminates
this problem and also sets the random number seed (non of the others did as
I recall) and is also adjusted by a static member variable. I know it's not
the most efficient or elegant piece of code on the planet but it works for
me. Incidentally you can call this code repeatedly and quickly without
generating duplicate passwords. Hope it helps.
private static int RandomAdjuster = 0;
public static String RandomPassword()
{
// Generate a random password
String Password = "";
int Seed = (int)(System.currentTimeMillis() % 20) + 1 + RandomAdjuster;
RandomAdjuster++;
String PassChars =
"Lz23456789AaBbCcDdEeFfGgHhJjKkMmNnMkPpQqRrSsTtUuVvWwXxYyZzf52abc";
Random Rand = new Random();
Rand.setSeed(System.currentTimeMillis() * Seed);
byte[] PassByte = new byte[10];
Rand.nextBytes(PassByte);
for (int i = 0; i < PassByte.length; i++) Password +=
PassChars.charAt(PassByte[i] & 0x3f);
return Password;
}
----- Original Message -----
From: "Anoop Kumar V" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 26, 2002 8:25 AM
Subject: Random string
> Hi,
> this is offtopic, and i am sorry .. but i hv a servlet here which resets
> users passwords in case they hv
> forgotten them. Is there someway i can generate random strings of length
say
> 6 characters long.
>
> again sorry,
> -anoop
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html