note 26687 deleted from function.chr by aharvey
| From: | aharvey@php.net | Date: | Fri, 24 May 2013 18:07:55 +0000 |
| Subject: | note 26687 deleted from function.chr by aharvey | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-194926@lists.php.net to get a copy of this message | ||
Note Submitter: gschafer at robandger dot com
----
Here's a small function I wrote up to generate random passwords using the chr() function.
<?php
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:
<?php
$password = randPass(10); //assigns 10-character password
?>
I found this useful in my early coding days... I'm sure someone else will too :D