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

203
Views
Bcrypt compare () siempre devuelve falso

He usado este código para comparar.

 UserSchema.pre('save', async function() { const salt = await bcrypt.genSalt(10) this.password = await bcrypt.hash(this.password, salt) }) UserSchema.methods.comparePassword = async function(candidatePassword) { const isMatch = await bcrypt.compare(candidatePassword, this.password) console.log(this.password); console.log(candidatePassword); return isMatch }

Siempre recibo un error de credenciales no válidas de la siguiente función de inicio de sesión. Lo he comprobado registrando las salidas. El problema radica en la función de comparación de contraseñas.

 const login = async(req, res) => { const { email, password } = req.body if (!email || !password) { throw new CustomError.BadRequestError('Please provide email and password') } const user = await User.findOne({ email }) if (!user) { throw new CustomError.UnauthenticatedError('Invalid Credentials') } const isPasswordCorrect = await user.comparePassword(password) if (!isPasswordCorrect) { throw new CustomError.UnauthenticatedError('Invalid Credentials') } if (!user.isVerified) { throw new CustomError.UnauthenticatedError('Please Verify Your Email ') } const tokenUSer = createTokenUser(user) attachCookiesToResponse({ res, user: tokenUSer }) res.status(StatusCodes.OK).json({ user: tokenUSer }) }
about 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!