Skip to content

Instantly share code, notes, and snippets.

@h3xx h3xx/AuthUtility.php
Last active Aug 29, 2015

Embed
What would you like to do?
Bad Code for generating a "random" password
/**
* Generate a random alphanumeric password
* precondition: len must be <= 32
* param len: length of the random password
* param enforce_rules: enforce password security rules
* returns: the random password
**/
public static function generateRandomPassword($len=8, $enforce_rules = false)
{
$count = 0;
$valid = true;
do {
$password = substr(md5(microtime()), 0, $len);
if ($enforce_rules)
{
try {
AuthUtility::checkPassword($password);
$valid = true;
}
catch (Exception $e) {
$valid = false;
}
}
} while ($valid === false && ++$count < 10);
if ($count >= 10)
{
Log::writeln("Unable to generate random password!");
$password = "6f33b5a3";
}
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.