I'm creating a back-end in NodeJS that will register a user with a hashed password to save in our database. I'm using bcrypt to hash the password and then bcrypt's compareSync when a user want to sign in with the created password.
I don't really see a point using Passport Local-strategy for this case since the only thing I'm doing in the local middleware is to use bcrypt's compareSync to see if the passwords are the same or not, which I can easily do in my own middleware and write that middleware to include the stuff I want.
The Passport middleware-code I'm using right now is:
passport.use(new passportLocal(function (username, password, done) {
r.table('user').filter({username: username}).limit(1).run()
.then(function (doc) {
if (doc._data && doc._data.length === 1) {
var data = doc._data[0][0];
if (data.password) {
if (bcrypt.compareSync(password, data.password)) {
done(null, data);
} else {
done(null, false, {message: 'Invalid username or password'})
}
} else {
done(null, false, {message: 'The user does not exist'});
}
} else {
done(null, false, {message: 'Invalid username or password'})
}
})
.catch(function (err) {
console.error(2222, err);
done(err);
});
}));
So the question is if I'm missing out on some security stuff that I will get with Passport instead of creating my own middleware that checks password with bcrypt?