/** * Create unpronounceable password * * This method creates a random unpronounceable password * * @access private * @param integer Length of the password * @param string Character which could be use in the * unpronounceable password ex : 'ABCDEFG' * or numeric, alphabetical or alphanumeric. * @return string Returns the password */ private static function _createUnpronounceable($length, $chars) { $password = ''; /** * List of character which could be use in the password */ switch ($chars) { case 'alphanumeric': $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; self::$numberOfPossibleCharacters = 62; break; case 'alphabetical': $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'; self::$numberOfPossibleCharacters = 52; break; case 'numeric': $chars = '0123456789'; self::$numberOfPossibleCharacters = 10; break; case '': $chars = '_#@%&ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; self::$numberOfPossibleCharacters = 67; break; default: /** * Some characters shouldn't be used */ $chars = trim($chars); $chars = str_replace(array('+', '|', '$', '^', '/', '\\', ','), '', $chars); self::$numberOfPossibleCharacters = strlen($chars); } /** * Generate password */ for ($i = 0; $i < $length; $i++) { $num = mt_rand(0, self::$numberOfPossibleCharacters - 1); $password .= $chars[$num]; } /** * Return password */ return $password; }