note 45560 added to function.rand
| From: | ftubino at yahoo dot com dot br | Date: | Fri, 10 Sep 2004 17:50:37 +0000 |
| Subject: | note 45560 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-76420@lists.php.net to get a copy of this message | ||
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
----
Manual Page -- http://www.php.net/manual/en/function.rand.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+45560
Delete -- http://master.php.net/manage/user-notes.php?action=delete+45560&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+45560&report=yes
Search -- http://master.php.net/manage/user-notes.php