RE: [PHP] Random Password Making.

2003-03-28 Thread Mark Cubitt
try this

function randpassword () {

$length = 6;

srand((double)microtime()*100);

$string = '';

while(strlen($string) != $length)  {
$type = rand(1,2);

if ($letterammount = 4) {$type = 1;}
if ($numammount = 2) {$type = 2;}

if($type == 1) {
$string = $string . chr(rand(48,57)); // 
numbers
$numammount = ($numammount + 1);
   }
if($type == 2) {
$lettertype = rand(1,2);

  if($lettertype == 1) {$string = $string .
chr(rand(65,90));} // uppercase letters
if($lettertype == 2) {$string = $string . 
chr(rand(97,122));} //
lowercase letters
$letterammount = ($letterammount + 1);
   }
}

return($string);
}

hope that helps

Regards

Mark Cubitt

 -Original Message-
 From: Philip J. Newman [mailto:[EMAIL PROTECTED]
 Sent: 28 March 2003 11:33
 To: [EMAIL PROTECTED]
 Subject: [PHP] Random Password Making.


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


 --
 Philip J. Newman.
 Head Developer
 [EMAIL PROTECTED]


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



 **
 
  This email has been virus checked by the Eclipse Internet
 MAILsafe service
 **
 
  www: http://www.eclipse.net.uk/email:
 [EMAIL PROTECTED]
 **
 




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



Re: [PHP] Random Password Making.

2003-03-28 Thread Steve Keller
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; $i4; $i++){
$thisPassArray[$i] = chr(rand(97,122));
}

// Pick 2 random numbers
for ($i=4; $i6; $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