Skip to content

Instantly share code, notes, and snippets.

@hongster
Last active October 2, 2015 11:32
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/ebe241e195960c6b73b6 to your computer and use it in GitHub Desktop.
Save hongster/ebe241e195960c6b73b6 to your computer and use it in GitHub Desktop.
Generate password/key that avoids user mistakes.
<?php
/**
* Generate random password of given length.
*
* @param int $length
* @return string
*/
private 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