J
J
jeruthadam2017-08-10 20:10:14
Cryptography
jeruthadam, 2017-08-10 20:10:14

Why bcrypt comparison doesn't work?

Why isMatch returns false, although candidatePassword returns the correct password, and the hash is stored in the database correctly too.

userSchema.methods.comparePassword = function (candidatePassword, cb) {
  bcrypt.compare(candidatePassword, this.password, function (err, isMatch) {
    if (err) {
      console.log('err')
      return cb (err)
    }
    console.log(candidatePassword)
    console.log(isMatch)
    cb (null, isMatch)
  })
}

There is a suspicion that he cannot take the password from the database due to asynchrony, can this be? Because I can't print this.password to the console

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question