<commit_before><?php
class SudoPage implements IPage {
    public function __construct(PageInfo &$page) {
    }
    public function template() {
        return Templates::findtemplate("default");
    }
    public function permission() {
        if ($_SESSION['sudo']) {
            Path::redirect($_GET['return']);
            return true;
        }

        $username = $_SESSION["username"];
        if (!$username) return false;

        $rank_res = Connection::query("SELECT Rank FROM users WHERE Username = ?", "s", array($username));
        $rank = $rank_res[0]["Rank"];
        return $rank >= 4;
    }
    public function subpages() {
        return false;
    }

    public function head(Head &$head) {
        $head->stylesheet("pages/login");
    }

    public function body() {
        $message = "Please re-enter your password. You won't need to do this for another hour.";

        if (isset($_POST['password'])) {
            // todo: password hashing
            $res = Connection::query("SELECT COUNT(*) AS Count FROM users WHERE Username = ? AND Password = ?", "ss", array(
                $_SESSION['username'],
                $_POST['password']
            ));

            if ($res[0]["Count"]) {
                $_SESSION["sudo"] = time();
                Path::redirect($_GET['return']);
            } else $message = "Invalid password. Please try again.";
        }

        ?>
<div id="loginBox">
    <form method="post">
        <h1>Entering sudo mode...</h1>
        <p><?php echo $message; ?></p>
        <input id="passField" type="password" name="password" placeholder="Password" /><br>
        <button type="submit">CONTINUE</button>
    </form>
</div>
<?php
    }
}<commit_msg>use password hashing for sudo page<commit_after><?php
class SudoPage implements IPage {
    public function __construct(PageInfo &$page) {
    }
    public function template() {
        return Templates::findtemplate("default");
    }
    public function permission() {
        if ($_SESSION['sudo']) {
            Path::redirect($_GET['return']);
            return true;
        }

        $username = $_SESSION["username"];
        if (!$username) return false;

        $rank_res = Connection::query("SELECT Rank FROM users WHERE Username = ?", "s", array($username));
        $rank = $rank_res[0]["Rank"];
        return $rank >= 4;
    }
    public function subpages() {
        return false;
    }

    public function head(Head &$head) {
        $head->stylesheet("pages/login");
    }

    public function body() {
        $message = "Please re-enter your password. You won't need to do this for another hour.";

        if (isset($_POST['password'])) {
            $res = Connection::query("SELECT Password FROM users WHERE Username = ?", "s", array($_SESSION['username']));

            Library::get("password");
            if (password_verify($_POST['password'], $res[0]["Password"])) {
                $_SESSION["sudo"] = time();
                Path::redirect($_GET['return']);
            } else $message = "Invalid password. Please try again.";
            
        }

        ?>
<div id="loginBox">
    <form method="post">
        <h1>Entering sudo mode...</h1>
        <p><?php echo $message; ?></p>
        <input id="passField" type="password" name="password" placeholder="Password" /><br>
        <button type="submit">CONTINUE</button>
    </form>
</div>
<?php
    }
}
{'fraction_non_alphanumeric': 0.16132823978842198, 'fraction_numerical': 0.0029385836027034967, 'mean_word_length': 2.317738791423002, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '274', 'n_tokens_mistral': 947, 'n_tokens_neox': 915, 'n_words': 244}