• Вырезать код авторизации?

    @1sset
    Люблю познавать новое
    else {
    
        if (isset($_GET['ref']) && user($_GET['ref']))
            $_SESSION['ref'] = intval($_GET['ref']);
    
        echo '<div class="title">Авторизация</div>';
    
        if (isset($_POST['auth'])) {
    
            $user = user($_POST['login'], 1);
    
            $error = '';
    
            if (isset($_SESSION['attempts']) && $_SESSION['attempts'] >= $sys['system']['err_attempts']) {
                if (empty($_POST['code'])) {
                    $error.= 'Введите код с картинки!<br/>';
                }
                elseif ($_SESSION['code'] != $_POST['code']) {
                    $error.= 'Код с картинки введен неверно!<br/>';
                }
            }
            if (!$error) {
                if (empty($_POST['login'])) {
                    $error.= 'Введите логин!<br/>';
                }
                elseif (!$user) {
                    $error.= 'Пользователь с данным логином не зарегистрирован!<br/>';
                }
                elseif ($user['ban'] > time()) {
                    $error.= 'Этот аккаунт заблокирован!<br/>';
                }
                elseif (!isset($_SESSION['attempts']) && $user['attempts'] >= $sys['system']['err_attempts'] && $user['captcha'] > time() - 3600 * $sys['system']['captcha_time']) {
                    $_SESSION['attempts'] = $user['attempts']; // включаем капчу
                    $error.= 'Вы не робот?<br/>';
                }
                elseif (empty($_POST['pass'])) {
                    $error.= 'Введите пароль!<br/>';
                }
                elseif (!password_verify($_POST['pass'], $user['pass'])) {
                    $_SESSION['attempts'] = isset($_SESSION['attempts']) ? $_SESSION['attempts'] + 1 : 1; // включаем капчу
                    CaptchaAuth($user); // учёт
                    $error.= 'Неверный пароль!<br/>';
                }
            }
            if ($error) {
                echo '<div class="menu">'.$error.'</div>';
            } else {
    
                $auth = bin2hex(random_bytes($sys['system']['authkey'])); // ключ авторизации
    
                if ($authlog->execute(array(time(), $user['id'], $ip, $ua, md5(md5($auth)), $_SESSION['attempts'] ?? 0))) {
    
                    /* авторизация */
    
                    $expire = isset($_POST['save']) ? time() + 3600 * 24 * 365 : 0;
    
                    setcookie('user_id', $user['id']);
                    setcookie('user_id', $user['id'], $expire, '/');
                    setcookie('pass', $user['pass']);
                    setcookie('pass', $user['pass'], $expire, '/');
                    setcookie('auth', $auth);
                    setcookie('auth', $auth, $expire, '/');
    
                    /* отключаем капчу */
    
                    CaptchaAuth($user, true);
    
                    unset($_SESSION['attempts']);
    
                    header('Location: /');
    
                } else {
                    echo '<div class="menu">Произошла ошибка!</div>';
                }
            }
        }
    
        echo '<div class="menu">
        <form action="" method="POST">
        Логин:<br/><input type="text" name="login"><br/>
        Пароль:<br/><input type="password" name="pass"><br/>
        '.(isset($_SESSION['attempts']) && $_SESSION['attempts'] >= $sys['system']['err_attempts'] ? '
        Код с картинки:<img id="captcha" src="/img/code.php" alt="check" onClick="UpCaptcha()"><br/>
        <input type="text" name="code"><br/>' : '').'
        <input type="submit" name="auth" value="Войти">
        <input type="checkbox" name="save" value="1">Запомнить
        </form></div>
        <div class="forlink"><a href="/reg" class="links"><img src="/img/reg.png" alt="reg">Зарегистрироваться</a></div>
        <div class="forlink"><a href="/forgot" class="links"><img src="/img/help.png" alt="help">Забыли пароль?</a></div>';
    
    }
    Ответ написан