6 * Contains user registration related functions.
9 * @copyright 2001-2019 WoltLab GmbH
10 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
11 * @package WoltLabSuite\Core\Util
13 final class UserRegistrationUtil
16 * Forbid creation of UserRegistrationUtil objects.
18 private function __construct()
24 * Returns true if the given name is a valid username.
26 * @param string $name username
29 public static function isValidUsername($name)
31 if (!UserUtil
::isValidUsername($name)) {
35 $length = \
mb_strlen($name);
36 if ($length < REGISTER_USERNAME_MIN_LENGTH ||
$length > REGISTER_USERNAME_MAX_LENGTH
) {
40 if (!self
::checkForbiddenUsernames($name)) {
44 if (REGISTER_USERNAME_FORCE_ASCII
) {
45 if (!\
preg_match('/^[\x20-\x7E]+$/', $name)) {
54 * Returns true if the given e-mail is a valid address.
56 * @param string $email
59 public static function isValidEmail($email)
61 return UserUtil
::isValidEmail($email) && self
::checkForbiddenEmails($email);
65 * Returns false if the given name is a forbidden username.
70 public static function checkForbiddenUsernames($name)
72 return StringUtil
::executeWordFilter($name, REGISTER_FORBIDDEN_USERNAMES
);
76 * Returns false if the given email is a forbidden email.
78 * @param string $email
81 public static function checkForbiddenEmails($email)
83 return StringUtil
::executeWordFilter(
85 REGISTER_FORBIDDEN_EMAILS
86 ) && (!StringUtil
::trim(REGISTER_ALLOWED_EMAILS
) ||
!StringUtil
::executeWordFilter(
88 REGISTER_ALLOWED_EMAILS
93 * Always returns true.
95 * @deprecated 5.3 - Take a look at the zxcvbn verdict from WoltLabSuite/Core/Ui/User/PasswordStrength.
97 public static function isSecurePassword($password)
103 * Returns the `passwordrules` attribute value.
105 * @see https://developer.apple.com/password-rules/
108 public static function getPasswordRulesAttributeValue()
110 return "minlength:8;";
114 * Generates a random activation code with the given length.
115 * Warning: A length greater than 9 is out of integer range.
120 public static function getActivationCode($length = 9)
122 return \random_int
(10 ** ($length - 1), 10 ** $length - 1);
126 * Generates a random field name.
128 * @param string $fieldName
131 public static function getRandomFieldName($fieldName)
133 $hash = StringUtil
::getRandomID();
135 return \
substr($hash, 0, \
mt_rand(8, 16));