• Модуль: main
  • Путь к файлу: ~/bitrix/modules/main/lib/security/authentication.php
  • Класс: BitrixMainSecurityAuthentication
  • Вызов: Authentication::updateDigest
protected function updateDigest($userId, $password)
{
	if (empty($userId))
		throw new MainArgumentNullException("userId");
	if (!MainTypeInt::isInteger($userId))
		throw new MainArgumentTypeException("userId");

	$userId = intval($userId);

	$connection = MainApplication::getDbConnection();
	$sqlHelper = $connection->getSqlHelper();

	$recordset = $connection->query(
		"SELECT U.LOGIN, UD.DIGEST_HA1 ".
		"FROM b_user U ".
		"   LEFT JOIN b_user_digest UD on U.ID = UD.USER_ID ".
		"WHERE U.ID = ".$userId
	);
	if ($record = $recordset->fetch())
	{
		$realm = MainConfigConfiguration::getValue("http_auth_realm");
		if (is_null($realm))
			$realm = "Bitrix Site Manager";

		$digest = md5($record["LOGIN"].':'.$realm.':'.$password);

		if ($record["DIGEST_HA1"] == '')
		{
			//new digest
			$connection->queryExecute(
				"INSERT INTO b_user_digest (USER_ID, DIGEST_HA1) ".
				"VALUES('".$userId."', '".$sqlHelper->forSql($digest)."')"
			);
		}
		else
		{
			//update digest (login, password or realm were changed)
			if ($record["DIGEST_HA1"] !== $digest)
			{
				$connection->queryExecute(
					"UPDATE b_user_digest SET ".
					"   DIGEST_HA1 = '".$sqlHelper->forSql($digest)."' ".
					"WHERE USER_ID = ".$userId
				);
			}
		}
	}
}