Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

184
Vistas
bcrypt compareSync returns false even they have same string

I am trying to make login functionality While I was creating the login function like this

login: (req,res) => {
const body = req.body;
getUserByEmail(body.email,(err,results)=>{
  if(err){
    console.log(err); 
  }
  if(!results){
    return res.json({
      sucess: 0,
      data: "Invalid email or password 1"
    });
  }
  console.log(body.pw);
  console.log(results.pw);
  const result = compareSync(body.pw,results.pw);
  console.log(result)
  if(result){
    results.pw = undefined;
    const jsontoken = sign({result: results},"1234413",{
      expiresIn: "1h"
    });
    return res.json({
      sucess: 1,
      message: "login sucessfully",
      token: jsontoken
    });
  }else{
    return res.json({
      sucess: 0,
      data: "Invalid email or password2"
    });
  }
});
}

Terminal Answer

I console log the body.pw and results.pw but seems like it give me same strings but I was not sure why it gives me false result even if I have same string for body.pw and results.pw

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

compareSync compares a password with a hash. You first need to hash the password before comparing it with the plain-text password.

First run

bcrypt.hash(myPlaintextPassword, saltRounds).then(function(hash) {
    // Store hash in your password DB.
});

Then you can compare

bcrypt.compare(myPlaintextPassword, hash).then(function(result) {
    // result == true
});
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda