我正在尝试在Node JS中构建日志记录应用程序。在这里,密码认证应用程序无法正常工作。当我输入用户名和密码时,它会出现以下错误并停止服务器。
this is the error.
Here is the code for authentication part
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;
if (isMatch) {
return done(null, user);
} else {
return done(null, false, {message: 'Invalid password'});
}
});
});
}));
这段代码可以给未知用户使用,但是无法用来比较用户名和密码。我在这里看不到任何错误。我希望能得到帮助来解决这个问题。
.comparePassword()
时,password
和user.password
的值是什么?看起来它抱怨user.password
是undefined
。 - Pointyuser.password
的值是多少? - Pointy