- Модуль: main
- Путь к файлу: ~/bitrix/modules/main/lib/security/authentication.php
- Класс: BitrixMainSecurityAuthentication
- Вызов: Authentication::getUserByHash
static function getUserByHash($login, $hash)
{
if (empty($login))
throw new MainArgumentNullException("login");
if (empty($hash))
throw new MainArgumentNullException("hash");
$event = new MainEvent(
"main",
"OnBeforeUserLoginByHash",
array("LOGIN" => $login, "HASH" => $hash)
);
$event->send();
if (($eventResults = $event->getResults()) !== null)
{
foreach ($eventResults as $eventResult)
{
if ($eventResult->getResultType() === MainEventResult::ERROR)
return null;
}
}
$connection = MainApplication::getDbConnection();
$sqlHelper = $connection->getSqlHelper();
$sql =
"SELECT U.ID, U.EXTERNAL_AUTH_ID ".
"FROM b_user U ".
"WHERE U.LOGIN = '".$sqlHelper->forSql($login, 50)."' ".
" AND U.ACTIVE = 'Y' ";
$isFound = false;
$user = null;
$recordset = $connection->query($sql);
while ($record = $recordset->fetch())
{
$user = new CurrentUser($record["ID"]);
$isExternal = ($record["EXTERNAL_AUTH_ID"] != '');
$storedHashId = static::getStoredHashId($user, $hash, $isExternal);
if ($storedHashId)
{
$isFound = true;
$user->setSessionHash($hash);
$user->setAuthType(static::AUTHENTICATED_BY_HASH);
break;
}
unset($user);
}
$isFound = $isFound && isset($user) && ($user instanceof CurrentUser);
$event = new BitrixMainEvent(
"main",
"OnAfterUserLoginByHash",
array(
"LOGIN" => $login,
"HASH" => $hash,
"USER_ID" => ($isFound && isset($user) ? $user->getUserId() : null)
)
);
$event->send();
if (!$isFound && (ConfigOption::get("main", "event_log_login_fail", "N") === "Y"))
CEventLog::log("SECURITY", "USER_LOGINBYHASH", "main", $login, "Unknown error");
return $isFound && isset($user) ? $user : null;
}