-
-
Notifications
You must be signed in to change notification settings - Fork 279
Closed
Description
I am storing the hashed password in the mongodb and then trying to compare the password in db with the user input password but this function is always returning false no matter whatever be the case.
var mongoose = require('mongoose');
var bcrypt = require('bcryptjs');
var express = require('express');
var router = express.Router();
var passport = require('passport');
var LocalStrategy = require('passport-local').Strategy;
module.exports.comparePassword = function(candidatePassword, hash, callback){
// Load hash from your password DB.
bcrypt.compare(candidatePassword, hash, function(err, isMatch) {
// res === true
if(err) throw err;
else return callback(null, isMatch);
});
}
getUserByUsername is working fine but the compare password is returning always "Invalid password"
passport.use(new LocalStrategy(
function(username, password, done) {
User.getUserByUsername(username, function(err, user){
if(err) throw err;
if(!user){
return done(null, false, {message: 'Unknown User'});
}
User.comparePassword(password, user.password, function(err, isMatch){
if(err) throw err;
//(this isMatch is always false)
if(!isMatch) {
return done(null, false, {message: 'Invalid password'});
}
return done(null, user);
});
});
}));
abhinayar and zishan344
Metadata
Metadata
Assignees
Labels
No labels