Skip to content

Instantly share code, notes, and snippets.

@FrancescaK
Created October 4, 2012 10:35
Show Gist options
  • Select an option

  • Save FrancescaK/3832839 to your computer and use it in GitHub Desktop.

Select an option

Save FrancescaK/3832839 to your computer and use it in GitHub Desktop.
comparing passwords
UserSchema.methods.comparePassword = function(candidatePassword, cb) {
bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
if (err) return cb(err);
cb(null, isMatch);
});
@meehow
Copy link
Copy Markdown

meehow commented May 15, 2014

I would add something like

if (this.isModified('password'))
  return cb(null, candidatePassword == this.password);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment