note 116713 deleted from function.shuffle by salathe
| From: | salathe@php.net | Date: | Thu, 19 Feb 2015 16:40:33 +0000 |
| Subject: | note 116713 deleted from function.shuffle by salathe | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201756@lists.php.net to get a copy of this message | ||
Note Submitter: victor_volpe at bol dot com dot br
----
Very Strong Password Generator. The output fulfills all security standards as in the website
www.passwordmeter.com (no relation with the website owner).
<?php
$password = array();
$characters[] = array('!', '"', '#', '$',
'%', '&', '\'', '(', ')', '*',
'+', ',', '-', '.', '/', ':',
';', '<', '=', '>', '?', '@',
'[', '\\', ']', '^', '_', '`',
'{', '|', '}', '~');
$characters[] = array('0', '1', '2', '3', '4',
'5', '6', '7', '8', '9');
$characters[] = array('A', 'B', 'C', 'D', 'E',
'F', 'G', 'H', 'I', 'J', 'K',
'L', 'M', 'N', 'O', 'P', 'Q',
'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z');
$characters[] = array('a', 'b', 'c', 'd', 'e',
'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'n', 'o', 'p', 'q',
'r', 's', 't', 'u', 'v', 'w',
'x', 'y', 'z');
shuffle($characters);
for ($i=0, $j=0; $i<20; $i++, $j++)
{
if ($j >= count($characters)) $j = 0;
while (true)
{
$char = $characters[$j][array_rand($characters[$j])];
if (!in_array(strtolower($char), array_map('strtolower', $password))) break;
}
$password[$i] = $char;
}
$offset = rand(1, count($password));
$password = array_merge(array_slice($password, $offset), array_slice($password, 0, $offset));
echo htmlspecialchars(implode('', $password));
?>