note 26687 added to function.chr
| From: | gschafer at robandger dot com | Date: | Fri, 08 Nov 2002 22:17:29 +0000 |
| Subject: | note 26687 added to function.chr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-39203@lists.php.net to get a copy of this message | ||
Here's a small function I wrote up to generate random passwords using the chr() function.
function randPass($len)
{
$pw = ''; //intialize to be blank
for($i=0;$i<$len;$i++)
{
switch(rand(1,3))
{
case 1: $pw.=chr(rand(48,57)); break; //0-9
case 2: $pw.=chr(rand(65,90)); break; //A-Z
case 3: $pw.=chr(rand(97,122)); break; //a-z
}
}
return $pw;
}
Example:
$password = randPass(10); //assigns 10-character password
I found this useful in my early coding days... I'm sure someone else will too :D
--
http://www.php.net/manual/en/function.chr.php
http://master.php.net/manage/user-notes.php?action=edit+26687
http://master.php.net/manage/user-notes.php?action=delete+26687
http://master.php.net/manage/user-notes.php?action=reject+26687