Проверка пароля пользователя на соответствие в 1С-Битрикс
Функция:
function IsUserPassword($userId, $password)
{
$rsUser = CUser::GetByID($userId);
$checkUserPassword = false;
if ($arUser = $rsUser->Fetch()) {
$hashLength = strlen($arUser["PASSWORD"]);
if ($hashLength > 100) {
$salt = substr($arUser["PASSWORD"], 3, 16);
$hashPassword = crypt($password, "$6$" . $salt . "$");
} else if ($hashLength > 32) {
$salt = substr($arUser["PASSWORD"], 0, $hashLength - 32);
$hashPassword = $salt . md5($salt . $password);
} else {
$salt = "";
$hashPassword = $arUser["PASSWORD"];
}
$checkUserPassword = ($hashPassword == $arUser["PASSWORD"]);
}
return $checkUserPassword;
}