php Password generator script

php-sniplets Add comments

Really Simple Password generator

This function produces comparatively secure random passwords. It is by no intends ideal, just it ought play
innermost noncrucial situations. The good matter is the generator efforts to make passwords that anyone can
suppose and selects letters that will not be incorrect for other people (specified the number “1″, an capital letter
“i” and a little “L”). To maintain the code short some of this practicality is really basic, but it is better than naught.

<?php
/**
* Renders somewhat more human-intelligible random passwords
*
* @param int $len
* @return string
*/
function makePassword($len = 8)
{
$vowel = array(‘a’, ‘e’, ‘i’, ‘o’, ‘u’, ‘y’);
$confusing = array(‘I’, ‘l’, ’1′, ‘O’, ’0′);
$replacement = array(‘A’, ‘k’, ’3′, ‘U’, ’9′);
$choice = array(0 => rand(0, 1), 1 => rand(0, 1), 2 => rand(0, 2));
$part = array(0 => ”, 1 => ”, 2 => ”);

if ($choice[0]) $part[0] = rand(1, rand(9,99));
if ($choice[1]) $part[2] = rand(1, rand(9,99));

$len -= (strlen($part[0]) + strlen($parts[2]));
for ($i = 0; $i < $len; $i++)
{
if ($i % 2 == 0) $part[1] .= chr(rand(97, 122));
else $part[1] .= $vowel[array_rand($vowel)];
}
if ($choice[2]) $part[1] = ucfirst($part[1]);
if ($choice[2] == 2) $part[1] = strrev($part[1]);

$r = $part[0] . $part[1] . $part[2];
$r = str_replace($confusing, $replacements, $r);
return $r;
}

/**
* Model:
*/

echo makePassword(12);
?>

Leave a Reply

You must be logged in to post a comment.

Impressum Entries RSS Log in