• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/classes/general/user.php
  • Класс: CAllUser
  • Вызов: CAllUser::CheckPasswordAgainstPolicy
static function CheckPasswordAgainstPolicy($password, $arPolicy, $userId = null)
{
	$errors = [];

	$passwordMinLength = intval($arPolicy['PASSWORD_LENGTH']);
	if ($passwordMinLength <= 0)
	{
		$passwordMinLength = 6;
	}
	if (mb_strlen($password) < $passwordMinLength)
	{
		$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_LENGTH', ['#LENGTH#' => $arPolicy['PASSWORD_LENGTH']]);
	}

	if (($arPolicy['PASSWORD_UPPERCASE'] === 'Y') && !preg_match('/[A-Z]/', $password))
	{
		$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_UPPERCASE');
	}

	if (($arPolicy['PASSWORD_LOWERCASE'] === 'Y') && !preg_match('/[a-z]/', $password))
	{
		$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_LOWERCASE');
	}

	if (($arPolicy['PASSWORD_DIGITS'] === 'Y') && !preg_match('/[0-9]/', $password))
	{
		$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_DIGITS');
	}

	if (($arPolicy['PASSWORD_PUNCTUATION'] === 'Y') && !preg_match('/[' . preg_quote(static::PASSWORD_SPECIAL_CHARS, '/') . ']/', $password))
	{
		$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_PUNCTUATION', ['#SPECIAL_CHARS#' => static::PASSWORD_SPECIAL_CHARS]);
	}

	if (($arPolicy['PASSWORD_CHECK_WEAK'] === 'Y'))
	{
		if (Option::get('main', 'custom_weak_passwords') === 'Y')
		{
			$uploadDir = Option::get('main', 'upload_dir', 'upload');
			$path = "{$_SERVER['DOCUMENT_ROOT']}/{$uploadDir}/main/weak_passwords";
		}
		else
		{
			$path = "{$_SERVER['DOCUMENT_ROOT']}/bitrix/modules/main/data/weak_passwords";
		}
		if (PolicyWeakPassword::exists($password, $path))
		{
			$errors[] = GetMessage('main_check_password_weak');
		}
	}

	if ($userId !== null && $arPolicy['PASSWORD_UNIQUE_COUNT'] > 0)
	{
		$passwords = UserPasswordTable::getUserPasswords($userId, $arPolicy['PASSWORD_UNIQUE_COUNT']);

		foreach ($passwords as $previousPassword)
		{
			if (Password::equals($previousPassword['PASSWORD'], $password))
			{
				$errors[] = GetMessage('MAIN_FUNCTION_REGISTER_PASSWORD_UNIQUE');
				break;
			}
		}
	}

	return $errors;
}