Skip to content

Instantly share code, notes, and snippets.

@jrsalunga
Created September 12, 2012 09:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jrsalunga/3705662 to your computer and use it in GitHub Desktop.
Save jrsalunga/3705662 to your computer and use it in GitHub Desktop.
php random password generator
// string of random a-z, A-Z, 0-9
function generatePassword($length = 8) {
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$count = mb_strlen($chars);
for ($i = 0, $result = ''; $i < $length; $i++) {
$index = rand(0, $count - 1);
$result .= mb_substr($chars, $index, 1);
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment