I\'m using Node.js + Express + Passport to create a simple authentication(local)
and what I\'ve reached so far that when a wrong username or password entered user is re
You are using
if (!user.validPassword(password)) {
return done(null, false, { message: 'Incorrect password.' });
}
but you haven't defined validPassword
method. Attach it to your schema:
var authSchema = mongoose.Schema({
username: 'string',
password: 'string'
});
authSchema.methods.validPassword = function( pwd ) {
// EXAMPLE CODE!
return ( this.password === pwd );
};
EDIT You've also incorrectly defined the schema. It should be:
var authSchema = mongoose.Schema({
username: String,
password: String
});
Note that both username
and password
should be String
type objects, not strings "string"
, if you know what I mean. :)