note 28474 added to function.rand
| From: | jnerin at svalero dot es | Date: | Tue, 14 Jan 2003 13:06:43 +0000 |
| Subject: | note 28474 added to function.rand | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-42121@lists.php.net to get a copy of this message | ||
Well, here is my way of making a password:
function generate_password ($length = 8, $valid_chars = "")
{
if($valid_chars=="")
{
$valid_chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_.";
}
$password="";
while($length>0)
{
$password.=$valid_chars[rand(0,strlen($valid_chars)-1)];
$length--;
}
return $password;
}
It's usefull, dead simple and flexible. And free ;-)
--
http://www.php.net/manual/en/function.rand.php
http://master.php.net/manage/user-notes.php?action=edit+28474
http://master.php.net/manage/user-notes.php?action=delete+28474
http://master.php.net/manage/user-notes.php?action=reject+28474