Skip to content

Instantly share code, notes, and snippets.

@hongster
Last active October 2, 2015 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hongster/789d735d19cb3ed03ae5 to your computer and use it in GitHub Desktop.
Save hongster/789d735d19cb3ed03ae5 to your computer and use it in GitHub Desktop.
Avoid using characters like (0,o,O,1,i,l) in generating random passwords.
<?php
function randomPassword($length = 6) {
// Non-ambiguous chars
$alphabet = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
$alphamax = strlen($alphabet) - 1;
$password = '';
for ($i = 0; $i < $length; $i++) {
$password .= $alphabet[mt_rand(0, $alphamax)];
}
return $password;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment