<commit_before>var express = require('express');
var router = express.Router();
var auth = require('basic-auth');
var config = require('../util/settings_handler').getConfig();


router.all('*', function(req, res, next) {
    if (config.use_authentication || config.use_api_key) {
        var credentials = auth(req);
        var key = req.query.api_key;
        //TODO: reroute to login
        if (!credentials && !key) {
            res.statusCode = 401;
            res.setHeader('WWW-Authenticate', 'Basic realm="example"');
            res.end('Access denied');
        } else {
            if (credentials) {
                for (var i = 0; i < config.users.length; i++) {
                    if (credentials.name == config.users[i].username && credentials.pass == config.users[i].password) {
                        next();
                        return;
                    }
                    res.statusCode = 400;
                    res.setHeader('WWW-Authenticate', 'Basic realm="example"');
                    res.end("Wrong credentials");
                    return;
                }
            } else {
                for (var i = 0; i < config.api_keys.length; i++) {
                    if (key === config.api_keys[i]) {
                        next()
                        return;
                    }
                }<commit_msg>Added reference to password-hash<commit_after>var express = require('express');
var router = express.Router();
var auth = require('basic-auth');
var config = require('../util/settings_handler').getConfig();
var hash = require('password-hash');


router.all('*', function(req, res, next) {
    if (config.use_authentication || config.use_api_key) {
        var credentials = auth(req);
        var key = req.query.api_key;
        //TODO: reroute to login
        if (!credentials && !key) {
            res.statusCode = 401;
            res.setHeader('WWW-Authenticate', 'Basic realm="example"');
            res.end('Access denied');
        } else {
            if (credentials) {
                for (var i = 0; i < config.users.length; i++) {
                    if (credentials.name == config.users[i].username && credentials.pass == config.users[i].password) {
                        next();
                        return;
                    }
                    res.statusCode = 400;
                    res.setHeader('WWW-Authenticate', 'Basic realm="example"');
                    res.end("Wrong credentials");
                    return;
                }
            } else {
                for (var i = 0; i < config.api_keys.length; i++) {
                    if (key === config.api_keys[i]) {
                        next()
                        return;
                    }
                }
{'fraction_non_alphanumeric': 0.13482335976928622, 'fraction_numerical': 0.005767844268204758, 'mean_word_length': 1.4172473867595818, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '738819', 'n_tokens_mistral': 758, 'n_tokens_neox': 704, 'n_words': 160}