<commit_before><?php

/**
 * Class Http_Auth
 * @method static Http_Auth create($salt, $users = array(), $title = 'Restricted Area')
 */
class Http_Auth extends Client {
    private $salt;
    private $users = array();
    public $title;

    const AREA_NOT_SET = 1;
    public static $conf = array();

    /**
     * @var Http_Auth_Dsn
     */
    protected $dsn;

    public function addUser($login, $passwordHash) {
        $this->dsn->users[$login] = $passwordHash;
        return $this;
    }

    public function addUsers($users) {
        $this->users = array_merge($this->users, $users);
        return $this;
    }

    public function isProvided() {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            return false;
        } else {
            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                return false;
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                return false;
            }
        }
        return true;
    }

    public function isProvidedDemandOnWrong() {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            return false;
        } else {
            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                $this->fatal('Unknown user ' . $_SERVER['PHP_AUTH_USER'] . print_r($this->dsn, 1));
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                $this->fatal('Bad password');
            }
        }
        return true;
    }

    public function demand($logout = false) {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header('WWW-Authenticate: Basic realm="' . $this->dsn->title . '"');
            header('HTTP/1.0 401 Unauthorized');
            echo 'Cancelled';
            exit;
        } else {

            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                $this->fatal('Unknown user ' . $_SERVER['PHP_AUTH_USER'] . print_r($this->dsn, 1));
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                $this->fatal('Bad password');
            }

            if ($logout) {
                $this->fatal('Logout');
            }
        }
    }

    public function logout() {
        $this->demand(true);
    }


    public function hash($login, $password) {
        return self::makeHash($login, $password, $this->dsn->salt);
    }

    public static function makeHash($login, $password, $salt) {
        return md5($login . $salt . $password);
    }

    private function fatal($message) {
        header('WWW-Authenticate: Basic realm="' . $this->dsn->title . '"');
        header('HTTP/1.0 401 Unauthorized');
        die($message);
    }

}

<commit_msg>auth debug<commit_after><?php

/**
 * Class Http_Auth
 * @method static Http_Auth create($salt, $users = array(), $title = 'Restricted Area')
 */
class Http_Auth extends Client {
    private $salt;
    private $users = array();
    public $title;

    const AREA_NOT_SET = 1;
    public static $conf = array();

    /**
     * @var Http_Auth_Dsn
     */
    protected $dsn;

    public function addUser($login, $passwordHash) {
        $this->dsn->users[$login] = $passwordHash;
        return $this;
    }

    public function addUsers($users) {
        $this->users = array_merge($this->users, $users);
        return $this;
    }

    public function isProvided() {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            return false;
        } else {
            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                return false;
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                return false;
            }
        }
        return true;
    }

    public function isProvidedDemandOnWrong() {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            return false;
        } else {
            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                $this->fatal('Unknown user ' . $_SERVER['PHP_AUTH_USER'] . print_r($this->dsn, 1));
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                $this->fatal('Bad password');
            }
        }
        return true;
    }

    public function demand($logout = false) {
        if (!isset($_SERVER['PHP_AUTH_USER'])) {
            header('WWW-Authenticate: Basic realm="' . $this->dsn->title . '"');
            header('HTTP/1.0 401 Unauthorized');
            echo 'Cancelled';
            exit;
        } else {

            if (!array_key_exists($_SERVER['PHP_AUTH_USER'], $this->dsn->users)) {
                $this->fatal('Unknown user ' . $_SERVER['PHP_AUTH_USER'] );
            } elseif ($this->dsn->users[$_SERVER['PHP_AUTH_USER']]
                != $this->hash($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) {
                $this->fatal('Bad password');
            }

            if ($logout) {
                $this->fatal('Logout');
            }
        }
    }

    public function logout() {
        $this->demand(true);
    }


    public function hash($login, $password) {
        return self::makeHash($login, $password, $this->dsn->salt);
    }

    public static function makeHash($login, $password, $salt) {
        return md5($login . $salt . $password);
    }

    private function fatal($message) {
        header('WWW-Authenticate: Basic realm="' . $this->dsn->title . '"');
        header('HTTP/1.0 401 Unauthorized');
        die($message);
    }

}


{'fraction_non_alphanumeric': 0.165681472724202, 'fraction_numerical': 0.004560040533693633, 'mean_word_length': 2.1037735849056602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 68, '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': '6178094', 'n_tokens_mistral': 1846, 'n_tokens_neox': 1753, 'n_words': 323}