Skip to content

Instantly share code, notes, and snippets.

@xpertspk
Created August 23, 2014 10:02
Show Gist options
  • Save xpertspk/74316c33bc9d5670f3bb to your computer and use it in GitHub Desktop.
Save xpertspk/74316c33bc9d5670f3bb to your computer and use it in GitHub Desktop.
PHP: generatePassword function
function generatePassword ($length = 10)
{
$password = "";
$possible = "0123456789bcdfghjkmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ";
$i = 0;
while ($i < $length) {
$char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
if (!strstr($password, $char)) {
$password .= $char;
$i++;
}
}
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment