Skip to content

Instantly share code, notes, and snippets.

@harshamv
Created January 5, 2013 06:18
Show Gist options
  • Save harshamv/4460107 to your computer and use it in GitHub Desktop.
Save harshamv/4460107 to your computer and use it in GitHub Desktop.
Random Password Generator
// Random Password Generator
function _RandomPasswordGenerator() {
// Create the meta-password
$sMetaPassword = "";
$CONFIG['security']['password_generator'] = array("C" => array('characters' =>
'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ', 'minimum' => 4,
'maximum' => 6), "S" => array('characters' => "!@()-_=+?*^&", 'minimum' => 0,
'maximum' => 0), "N" => array('characters' => '1234567890', 'minimum' => 2,
'maximum' => 2));
$ahPasswordGenerator = $CONFIG['security']['password_generator'];
foreach ($ahPasswordGenerator as $cToken => $ahPasswordSeed)
$sMetaPassword .= str_repeat($cToken, rand($ahPasswordSeed['minimum'], $ahPasswordSeed['maximum']));
$sMetaPassword = str_shuffle($sMetaPassword);
// Create the real password
$arBuffer = array();
for ($i = 0; $i < strlen($sMetaPassword); $i++)
$arBuffer[] = $ahPasswordGenerator[(string )$sMetaPassword[$i]]['characters'][rand(0,
strlen($ahPasswordGenerator[$sMetaPassword[$i]]['characters']) - 1)];
return implode("", $arBuffer);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment