public static function generatePassword($length = 8) { $upperPattern = '/([A-Z])+/'; $lowerPattern = '/([a-z])+/'; $numberPattern = '/([0-9])+/'; while (true) { $pass = CommonFunction::generateRawPassword($length); if (preg_match($upperPattern, $pass, $matches) && preg_match($lowerPattern, $pass, $matches) && preg_match($numberPattern, $pass, $matches)) { break; } } return $pass; }