At 3/28/2003 11:32 PM, Philip J. Newman wrote:

> Whats the best way to make a random password with 4 letters and 2 numbers?

I don't know what the "best" way is, but I had fun doing this one. I filled the first 4 elements of an array with random letters by using the minimum ASCII value of a letter as my random base, and the maximum ASCII letter value as my random max (97 is "a" and 122 is "z"). Then did the same thing to pick two numbers and add those to the array as well. Then I shuffled the array to juggle the order the letters and numbers are in, and imploded it into a single string. Viola.

<?
// Pick 4 random letters
        for ($i=0; $i<4; $i++){
                $thisPassArray[$i] = chr(rand(97,122));
        }
        
// Pick 2 random numbers
        for ($i=4; $i<6; $i++){
                $thisPassArray[$i] = chr(rand(48,57));
        }
        
// Randomize their order
        shuffle($thisPassArray);
        
// Implode the array into a password
        $thisPass = implode("",$thisPassArray);
        
// Echo the password
        echo $thisPass;
?>

Now, of course, I didn't do any validation, ie. making sure the letters don't repeat, including capital letters, or anything like that. But, hopefully, this will give you a place to start.
--
S. Keller
UI Engineer
The Health TV Channel, Inc.
(a non - profit organization)
3820 Lake Otis Pkwy.
Anchorage, AK 99508
907.770.6200 ext.220
907.336.6205 (fax)
Email: [EMAIL PROTECTED]
Web: www.healthtvchannel.org



-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to