Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
function comparePasswords(password, hash, callback) {
bcrypt.compare(crypto.createHash('sha256').update(password).digest('hex'), hash, callback);
}
new LocalStrategy(function getUserPassport(username, password, done) {
User.findOne({
'emails.address': username,
}, (findError, userModel) => {
if (findError) {
return done(findError);
}
if (!userModel) {
return done(null, false, { message: 'Incorrect username.' });
}
const user = userModel.toJSON();
comparePasswords(password, user.services.password.bcrypt, (hashError, goodPassword) => {
if (hashError) {
return done(hashError);
}
if (!goodPassword) {
return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
});
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment