} CHTTP::SetStatus("401 Unauthorized"); } else { $answer = array("success" => true, "sessionId" => session_id(), "bitrixSessionId" => bitrix_sessid()); if (($_POST['renew_password'] == 'y' || $_POST['otp'] != '') && $USER->GetParam("APPLICATION_ID") === null) { $code = ''; if (strlen($_POST['user_os_mark']) > 0) { $code = md5($_POST['user_os_mark'] . $_POST['user_account']); } if ($code != '') { $orm = ApplicationPasswordTable::getList(array('select' => array('ID'), 'filter' => array('USER_ID' => $USER->GetID(), 'CODE' => $code))); if ($row = $orm->fetch()) { ApplicationPasswordTable::delete($row['ID']); } } $password = ApplicationPasswordTable::generatePassword(); $res = ApplicationPasswordTable::add(array('USER_ID' => $USER->GetID(), 'APPLICATION_ID' => 'desktop', 'PASSWORD' => $password, 'DATE_CREATE' => new Main\Type\DateTime(), 'CODE' => $code, 'COMMENT' => GetMessage('DESKTOP_APP_GENERATOR'), 'SYSCOMMENT' => GetMessage('DESKTOP_APP_TITE'))); if ($res->isSuccess()) { $answer["appPassword"] = $password; } } } if (isset($_REQUEST['json']) && $_REQUEST['json'] == 'y') { header('Content-Type: application/json'); echo Main\Web\Json::encode($answer); } else { echo toJsObject($answer); } function toJsObject(array $answer) { $answerParts = array();