note 58411 deleted from function.str-shuffle by googleguy
| From: | googleguy@php.net | Date: | Tue, 22 Oct 2013 14:54:25 +0000 |
| Subject: | note 58411 deleted from function.str-shuffle by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-197220@lists.php.net to get a copy of this message | ||
Note Submitter: nmoyroud at teledetection dot fr
----
Just another update to password builder function. With this version, you can choose the number of
alphanumeric characters to add and the number of non-alphanumeric characters. You obtain a more
secure password. You can add another characters to the non-alphanumeric list if you need.
If you want a password with 8 alphanumeric and 3 non-alphanumeric characters in a random order, just
call :
random_passwd(8,3);
function generatePasswd($numAlpha=6,$numNonAlpha=2) {
$pwd = '';
$listAlpha = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$listNonAlpha = ',;:!?.$/*-+&@_+;./*&?$-!,';
$start = mt_rand(1, (strlen($listAlpha)-$numAlpha));
$string = str_shuffle($listAlpha);
$pwd .= substr($string,$start,$numAlpha);
$start = mt_rand(1, (strlen($listNonAlpha)-$numNonAlpha));
$string = str_shuffle($listNonAlpha);
$pwd .= substr($string,$start,$numNonAlpha);
return str_shuffle($pwd);
}