I am new to nodejs and mongodb please help!
I am fetching two values from a sample login page and based on the email id, I am searching through the collection to check if the password matches
This is the js file making the call for validating
exports.profile = function(req, res) {
var email=req.body.email;
var password=req.body.password;
var validUser=validate.isValidUser(email,password);
console.log(validUser);
res.sendfile(path.join(__dirname, '../public', 'profile.html'));};
This is my js file to check if the password matches
exports.isValidUser = function(emailEntered, passEntered) {
var pass;
mongoose.connect('mongodb://localhost/registration');
User.findOne({
email : emailEntered
}, function(err, doc) {
if (err) {
console.log(err);
} else {
pass = doc.password;
console.log(pass);
console.log(passEntered);
mongoose.connection.close();
}
console.log('Disconnected from server successfully');
});
if (passEntered===pass) {
return true;
}
else {
return false;
}};
Every time I run it even if the password matches, it is returning false.