/** * Generates a random activation code with the given length. * Warning: A length greater than 9 is out of integer range. * * @param integer $length * @return integer */ public static function getActivationCode($length = 9) { return MathUtil::getRandomValue(pow(10, $length - 1), pow(10, $length) - 1); }
/** * Generates a random user password with the given character length. * * @param integer $length * @return string */ public static function getRandomPassword($length = 8) { $availableCharacters = array('abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '0123456789', '+#-.,;:?!'); $password = ''; $type = 0; for ($i = 0; $i < $length; $i++) { $type = $i % 4 == 0 ? 0 : $type + 1; $password .= substr($availableCharacters[$type], MathUtil::getRandomValue(0, strlen($availableCharacters[$type]) - 1), 1); } return str_shuffle($password); }
/** * Generates a random user password with the given character length. * * @param integer $length * @return string new password */ public static function getNewPassword($length = 9) { static $availableCharacters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+#-.,;:?!'; $password = ''; for ($i = 0; $i < $length; $i++) { $password .= substr($availableCharacters, MathUtil::getRandomValue(0, strlen($availableCharacters) - 1), 1); } return $password; }