note 86469 added to function.chr
| From: | scott at quinlan dot co dot nz | Date: | Tue, 21 Oct 2008 04:51:57 +0000 |
| Subject: | note 86469 added to function.chr | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145532@lists.php.net to get a copy of this message | ||
Secure password generator with a variable maximum amount of symbols.
<?php
function passwdGen($minLength = 8, $maxLength = 12, $maxSymbols = 2)
{
$symbolCount = 0;
srand((double)microtime() * 1000003);
for ($i = 0; $i < rand($minLength, $maxLength); $i++)
{
do
{
$char = rand(33, 126);
$symbolCount += $isSymbol = (!in_array($char, range(48, 57)) && !in_array($char,
range(65, 90)) && !in_array($char, range(97, 122)));
if ($symbolCount <= $maxSymbols || !$isSymbol)
{
break;
}
}
while (true);
$passwd = sprintf('%s%c', isset($passwd) ? $passwd : NULL, $char);
}
return $passwd;
}
?>
----
Server IP: 202.89.58.1
Probable Submitter: 202.191.34.4
----
Manual Page -- http://www.php.net/manual/en/function.chr.php
Edit -- https://master.php.net/note/edit/86469
Del: integrated -- https://master.php.net/note/delete/86469/integrated
Del: useless -- https://master.php.net/note/delete/86469/useless
Del: bad code -- https://master.php.net/note/delete/86469/bad+code
Del: spam -- https://master.php.net/note/delete/86469/spam
Del: non-english -- https://master.php.net/note/delete/86469/non-english
Del: in docs -- https://master.php.net/note/delete/86469/in+docs
Del: other reasons-- https://master.php.net/note/delete/86469
Reject -- https://master.php.net/note/reject/86469
Search -- https://master.php.net/manage/user-notes.php