<commit_before><?php

class User
{

    /**
     * Default values stored & session info
     * @method __construct
     */
    public function __construct()
    {
        $this->database = new Database();
        $this->basic = new Basic();

        if (!isset($_SESSION)) {
            session_set_cookie_params(6000000, '/', null, false, true);
            session_start();
        }
    }

    /**
     * Get or create a CSRF token
     * @method getCsrf
     * @return string 32 character CSRF token
     */
    public function getCsrf(): string
    {
        return $_SESSION['csrfToken'] ?? $_SESSION['csrfToken'] = bin2hex(
                openssl_random_pseudo_bytes(32)
            );
    }

    /**
     * Check credentials and login user
     * @method install
     * @param string $password <PASSWORD>
     * @param string $code 2FA code
     * @return array|string
     */
    public function login($password, $code)
    {
        if ($this->isLoggedIn()) {
            return ['redirect' => 'dashboard'];
        }

        $passwordHash = $this->database->fetchSetting('password');
        $secret = $this->database->fetchSetting('secret');

        if (!password_verify($password, $passwordHash)) {
            return 'The password you entered is not valid.';
        }

        if (strlen($secret) === 16 && $this->basic->getCode($secret) != $code) {
            return 'The code is incorrect.';
        }

        $this->createSession();

        if (isset($_SESSION['redirect'])) {
            return ['redirect' => $_SESSION['redirect']];
        }

        return ['redirect' => 'dashboard'];
    }

    /**
     * Check if user is logged in
     * @method isLoggedIn
     * @return boolean If user is logged in true/false
     */
    public function isLoggedIn(): bool
    {
        return isset($_SESSION['login']) ? true : false;
    }

    /**
     * Set settings in session cookie
     * @method createSession
     */
    public function createSession(): void
    {
        $_SESSION['login'] = true;
    }

    /**
     * Install website
     * @method install
     * @param string $password Password for login
     * @param string $email Email for email alert
     * @return array|string
     */
    public function install($password, $email)
    {
        if ($this->database->isInstalled() === true) {
            return 'This website is already installed.';
        }

        if (strlen($password) < 8) {
            return 'The password needs to be at least 8 characters long.';
        }

        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return 'This is not a correct email address.';
        }

        $this->database->query(
            'CREATE TABLE IF NOT EXISTS `settings` (`id` int(11) NOT NULL AUTO_INCREMENT,`setting` varchar(500) NOT NULL,`value` text NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
        );
        $this->database->query(
            'CREATE TABLE IF NOT EXISTS `reports` (`id` int(11) NOT NULL AUTO_INCREMENT,`shareid` VARCHAR(50) NOT NULL,`cookies` text,`dom` longtext,`origin` varchar(500) DEFAULT NULL,`referer` varchar(500) DEFAULT NULL,`payload` varchar(500) DEFAULT NULL,`uri` varchar(500) DEFAULT NULL,`user-agent` varchar(500) DEFAULT NULL,`ip` varchar(50) DEFAULT NULL,`time` int(11) DEFAULT NULL,`archive` int(11) DEFAULT 0,`screenshot` LONGTEXT NULL DEFAULT NULL,`localstorage` LONGTEXT NULL DEFAULT NULL, `sessionstorage` LONGTEXT NULL DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;'
        );
        $this->database->query(
            'INSERT INTO `settings` (`setting`, `value`) VALUES ("filter-save", "0"),("filter-alert", "0"),("dompart", "500"),("timezone", "Europe/Amsterdam"),("customjs", ""),("blocked-domains", ""),("notepad", "Welcome :-)"),("secret", ""),("killswitch", ""),("collect_uri", "1"), ("collect_ip", "1"), ("collect_referer", "1"), ("collect_user-agent", "1"), ("collect_cookies", "1"),("collect_localstorage", "1"), ("collect_sessionstorage", "1"), ("collect_dom", "1"), ("collect_origin", "1"), ("collect_screenshot", "0"),("theme", "classic"),("whitelist-domains", ""), ("telegram-bottoken", ""), ("telegram-chatid", ""), ("callback-url", ""), ("alert-mail", "1"), ("alert-telegram", "0"), ("alert-callback", "0"), ("adminurl", "manage"), ("extract-pages", "");'
        );
        $this->database->fetch(
            'INSERT INTO `settings` (`setting`, `value`) VALUES ("password", :password),("email", :email),("payload-domain", :domain),("version", :version),("emailfrom", "ezXSS");',
            [
                ':password' => password_hash($password, <PASSWORD>, ['cost' => 11]),
                ':email' => $email,
                ':domain' => $this->basic->domain(),
                ':version' => version
            ]
        );

        $this->createSession();
        return ['redirect' => 'dashboard'];
    }<commit_msg>Update default values for installation<commit_after><?php

class User
{

    /**
     * Default values stored & session info
     * @method __construct
     */
    public function __construct()
    {
        $this->database = new Database();
        $this->basic = new Basic();

        if (!isset($_SESSION)) {
            session_set_cookie_params(6000000, '/', null, false, true);
            session_start();
        }
    }

    /**
     * Get or create a CSRF token
     * @method getCsrf
     * @return string 32 character CSRF token
     */
    public function getCsrf(): string
    {
        return $_SESSION['csrfToken'] ?? $_SESSION['csrfToken'] = bin2hex(
                openssl_random_pseudo_bytes(32)
            );
    }

    /**
     * Check credentials and login user
     * @method install
     * @param string $password Password for login
     * @param string $code 2FA code
     * @return array|string
     */
    public function login($password, $code)
    {
        if ($this->isLoggedIn()) {
            return ['redirect' => 'dashboard'];
        }

        $passwordHash = $this->database->fetchSetting('password');
        $secret = $this->database->fetchSetting('secret');

        if (!password_verify($password, $passwordHash)) {
            return 'The password you entered is not valid.';
        }

        if (strlen($secret) === 16 && $this->basic->getCode($secret) != $code) {
            return 'The code is incorrect.';
        }

        $this->createSession();

        if (isset($_SESSION['redirect'])) {
            return ['redirect' => $_SESSION['redirect']];
        }

        return ['redirect' => 'dashboard'];
    }

    /**
     * Check if user is logged in
     * @method isLoggedIn
     * @return boolean If user is logged in true/false
     */
    public function isLoggedIn(): bool
    {
        return isset($_SESSION['login']) ? true : false;
    }

    /**
     * Set settings in session cookie
     * @method createSession
     */
    public function createSession(): void
    {
        $_SESSION['login'] = true;
    }

    /**
     * Install website
     * @method install
     * @param string $password <PASSWORD>
     * @param string $email Email for email alert
     * @return array|string
     */
    public function install($password, $email)
    {
        if ($this->database->isInstalled() === true) {
            return 'This website is already installed.';
        }

        if (strlen($password) < 8) {
            return 'The password needs to be at least 8 characters long.';
        }

        if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            return 'This is not a correct email address.';
        }

        $this->database->query(
            'CREATE TABLE IF NOT EXISTS `settings` (`id` int(11) NOT NULL AUTO_INCREMENT,`setting` varchar(500) NOT NULL,`value` text NOT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;'
        );
        $this->database->query(
            'CREATE TABLE IF NOT EXISTS `reports` (`id` int(11) NOT NULL AUTO_INCREMENT,`shareid` VARCHAR(50) NOT NULL,`cookies` text,`dom` longtext,`origin` varchar(500) DEFAULT NULL,`referer` varchar(1000) DEFAULT NULL,`payload` varchar(500) DEFAULT NULL,`uri` varchar(1000) DEFAULT NULL,`user-agent` varchar(500) DEFAULT NULL,`ip` varchar(50) DEFAULT NULL,`time` int(11) DEFAULT NULL,`archive` int(11) DEFAULT 0,`screenshot` LONGTEXT NULL DEFAULT NULL,`localstorage` LONGTEXT NULL DEFAULT NULL, `sessionstorage` LONGTEXT NULL DEFAULT NULL,PRIMARY KEY (`id`)) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=0;'
        );
        $this->database->query(
            'INSERT INTO `settings` (`setting`, `value`) VALUES ("filter-save", "0"),("filter-alert", "0"),("dompart", "500"),("timezone", "Europe/Amsterdam"),("customjs", ""),("blocked-domains", ""),("notepad", "Welcome :-)"),("secret", ""),("killswitch", ""),("collect_uri", "1"), ("collect_ip", "1"), ("collect_referer", "1"), ("collect_user-agent", "1"), ("collect_cookies", "1"),("collect_localstorage", "1"), ("collect_sessionstorage", "1"), ("collect_dom", "1"), ("collect_origin", "1"), ("collect_screenshot", "0"),("theme", "classic"),("whitelist-domains", ""), ("telegram-bottoken", ""), ("telegram-chatid", ""), ("callback-url", ""), ("alert-mail", "1"), ("alert-telegram", "0"), ("alert-callback", "0"), ("adminurl", "manage"), ("extract-pages", "");'
        );
        $this->database->fetch(
            'INSERT INTO `settings` (`setting`, `value`) VALUES ("password", :password),("email", :email),("payload-domain", :domain),("version", :version),("emailfrom", "ezXSS");',
            [
                ':password' => password_hash($password, PASSWORD_BCRYPT, ['cost' => 11]),
                ':email' => $email,
                ':domain' => $this->basic->domain(),
                ':version' => version
            ]
        );

        $this->createSession();
        return ['redirect' => 'dashboard'];
    }
{'fraction_non_alphanumeric': 0.17245557350565427, 'fraction_numerical': 0.01474151857835218, 'mean_word_length': 2.7504733055660733, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 70, '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': '2039452', 'n_tokens_mistral': 3034, 'n_tokens_neox': 2858, 'n_words': 734}