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

120
Vistas
Problems with bcrypt hash encryption - node.js

I'm having trouble logging in, with hash, I made the call in the create method, and it's working normally, but in the login no, I saw errors similar to mine here on the stack, but I didn't understand how to implement it, could you give a strength? the error message it returns is "Error: data and hash arguments required" the line where the error is would be do: const validPass

const connection = require('../database/connection');
const bcrypt = require('bcrypt');

async create(request, response){
        const {id, email, password, cpf, name, lastName, cellphone} = request.body;

        let salt = await bcrypt.genSaltSync(10);
        let hash = bcrypt.hashSync(password, salt);

        const newUser = await connection('login').insert({
            id,
            email,
            password:hash,
            cpf,
            name,
            lastName,
            cellphone,
        });
        return response.json({id: newUser[0], token: hash.toString('hex')});
        
    },

async login(request, response){
        const {email, password} = request.body;

        const user = await connection('login').first('*').where({email:email});

        if(user){
            const validPass = await bcrypt.compareSync(password, user.hash);
            if(validPass){
                response.status(200).json('valid Email and pass!');
            }else{
                response.json('Wrong pass!')
            }
        }else{
            response.status(400).json({error: 'No user foung with this E-mail'});
        }

        return response.json(user);
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In this line:

const validPass = await bcrypt.compareSync(password, user.hash);

Change user.hash to user.password.

Extra note: You don't need those awaits before the synchronous function calls.

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