<commit_before>'use strict';

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var express = require('express');
var mongoose = require('mongoose');
var UserDetails = require('../models/users.js');

module.exports = function (app, db) {
    
app.get('/login', function(req, res) {
  res.sendFile(process.cwd() + '/public/login.html');
});

app.post('/login',
  passport.authenticate('local', {
    successRedirect: '/loginSuccess',
    failureRedirect: '/loginFailure'
  })
);

app.get('/loginFailure', function(req, res, next) {
  res.send('Failed to authenticate');
});

app.get('/loginSuccess', function(req, res, next) {
  res.send('Successfully authenticated');
});

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

passport.use(new LocalStrategy(function(username, password, done) {
  process.nextTick(function() {
     UserDetails.findOne({
      'username': username, 
    }, function(err, user) {
      if (err) {
        return done(err);
      }

      if (!user) {
        return done(null, false);
      }

      if (user.password != password) {
        return done(null, false);
      }

      return done(null, user);
    });
  });
}));

};<commit_msg>password hashing and login complete<commit_after>'use strict';

var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
var express = require('express');
var mongoose = require('mongoose');
var UserDetails = require('../models/users.js');

module.exports = function (app, db) {
    
app.get('/login', function(req, res) {
  res.sendFile(process.cwd() + '/public/login.html');
});

app.post('/login',
  passport.authenticate('local', {
    successRedirect: '/loginSuccess',
    failureRedirect: '/loginFailure'
  })
);

app.get('/loginFailure', function(req, res, next) {
  res.send('Failed to authenticate');
});

app.get('/loginSuccess', function(req, res, next) {
  res.send('Successfully authenticated');
});

passport.serializeUser(function(user, done) {
  done(null, user);
});

passport.deserializeUser(function(user, done) {
  done(null, user);
});

passport.use(new LocalStrategy(function(username, password, done) {
  process.nextTick(function() {
     UserDetails.findOne({
      'username': username, 
    }, function(err, user) {
      if (err) {
        return done(err);
      }

      if (!user) {
        return done(null, false);
      }


       user.comparePassword(password, function(err, isMatch) {
        if (err) throw err;
              console.log( isMatch); //
            if(!isMatch){
              return done(null, false);
            }
          });

      return done(null, user);
    });
  });
}));

};
{'fraction_non_alphanumeric': 0.1753691033489377, 'fraction_numerical': 0.0, 'mean_word_length': 3.4235668789808917, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5788564', 'n_tokens_mistral': 872, 'n_tokens_neox': 860, 'n_words': 173}