note 45560 deleted from function.rand by aidan
| From: | aidan@php.net | Date: | Sat, 11 Sep 2004 07:39:07 +0000 |
| Subject: | note 45560 deleted from function.rand by aidan | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-76444@lists.php.net to get a copy of this message | ||
Note Submitter: ftubino at yahoo dot com dot br
----
Here's another way to generate random passwords, with characters between A-Z, a-z or 0-9:
<?php
function create_password($length = "6"){
$new_pass = "";
for($i=0; $i<$length; $i++) {
$kind=rand(1,3);
switch ($kind){
case 1:
$char=chr(rand(48,57)); //0-9
break;
case 2:
$char=chr(rand(65,90)); //A-Z
break;
default:
$char=chr(rand(97,122)); //a-z
break;
}
$new_pass .= $char;
}
return $new_pass;
}
$password=create_password();
echo "Password: ".$password;
?>
It's working very very well.
Regards,
Flávio Tubino
Blumenau - Brazil