<commit_before>var basicAuth = require('basic-auth');
var config = require('config');

var auth = { };

auth.viewAuth = function() {
  return function(req, res, next) {
    var user = basicAuth(req);

    var username = config.get('credentials.view.username');
    var password = config.get('credentials.view.password');

    if (!user || user.name !== username || user.pass !== password) {
      res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
      res.sendStatus(401);
    } else {
      next();
    }
  }
};

auth.createAuth = function() {
  return function(req, res, next) {
    var user = basicAuth(req);

    var username = config.get('credentials.create.username');
    var password = config.get('<PASSWORD>.create.password');

    if (!user || user.name !== username || user.pass !== password) {
      res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
      res.sendStatus(401);
    } else {
      next();
    }
  }
};

module.exports = auth;<commit_msg>Removed code duplication in auth.js<commit_after>var basicAuth = require('basic-auth');
var config = require('config');

var auth = { };

var authMehtod = function(req, res, next, credentials) {
  var user = basicAuth(req);
  if (!user || user.name !== credentials.username || user.pass !== <PASSWORD>) {
    res.set('WWW-Authenticate', 'Basic realm=Authorization Required');
    res.sendStatus(401);
  } else {
    next();
  }
};

auth.viewAuth = function() {
  return function(req, res, next) {
    authMehtod(req, res, next, config.get('credentials.view'));
  }
};

auth.createAuth = function() {
  return function(req, res, next) {
    authMehtod(req, res, next, config.get('credentials.create'));
  }
};

module.exports = auth;
{'fraction_non_alphanumeric': 0.170999422299249, 'fraction_numerical': 0.005199306759098787, 'mean_word_length': 3.693766937669377, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5113348', 'n_tokens_mistral': 552, 'n_tokens_neox': 542, 'n_words': 121}