Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

634
Views
Bcrypt compare method is not returning true when hash password is stored in the database
userSchema.statics.findByCredentials = async (email, password) => {
    const user = await User.findOne({ email })

    if (!user) {
        throw new Error('no user found!')
    }

    const isMatch = await bcrypt.compare(password, user.password)

    if (!isMatch) {
        throw new Error('invalid credentials!')
    }

    return user
}

The above code is matching the hash password that is stored in the database with a plain text password but it always returns false. so I tried this & it's working, could anyone explain to me; why this code is working & the above one is not working?

const bcrypt = require('bcryptjs')
const encription = async () => {
const password = 'abc1234';
console.log('plain password: ', password);

const hashPass = await bcrypt.hash(password, 8);
console.log(`hash password: ${hashPass}`);

const isValidPass = await bcrypt.compare(password, hashPass);
console.log(`is valid: ${isValidPass}`);
}

encription();
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!