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

167
Vistas
bcrypt is not functioning properly

this is the thunder client you can see at the password field it is not hashedHere I am using bcrypt package but when I try to create user with thunder client at visual studio it is not performing hashing, the password is not storing with hash value as I have written the code below const salt and const secPass.

This is nodejs, expresjs:

const express = require('express');
const router = express.Router();
const User = require('../models/User');
const { body, validationResult } = require('express-validator');
const bcrypt = require('bcryptjs');


router.post('/',[
    body('name').isLength({ min: 3 }),
    body('email').isEmail(),
    body('password').isLength({ min: 5 })
    
] ,async(req,res)=>{
  //if there are any errors it sends bad request 400
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    //check wether user exists with this email already
    try{
let user = await User.findOne({email: req.body.email});
if(user){

  return res.status(400).json({error: 'sorry user with this email already exists'})
}

const salt = await bcrypt.genSalt(10);
const secPass = await bcrypt.hash(req.body.password, salt) 

    user = await User.create({
        name: req.body.name,
        email: req.body.email,
        password: req.body.password
      })
      //this is for understanding purpose of other code
    //   .then(user => res.json(user))
    //   .catch(err =>{console.log(err)
    // res.json({error: 'email already exists', message: err.message})});
    res.json(user)
    } 
catch (error){
console.error(error.message);
res.status(500).send('some error occured')
}
})

module.exports = router

This is package.json file:

{
  "name": "my-app",
  "version": "1.0.0",
  "description": "project contains backend and front end",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start-nodemon": "nodemon ./index.js"
  },
  "author": "yashrith",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "express": "^4.17.1",
    "express-validator": "^6.13.0",
    "mongoose": "^6.0.13"
  },
  "devDependencies": {
    "nodemon": "^2.0.15"
  }
}

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

0

You are hashing your password but not using it. Try with this.


const express = require('express');
const router = express.Router();
const User = require('../models/User');
const { body, validationResult } = require('express-validator');
const bcrypt = require('bcryptjs');


router.post('/',[
    body('name').isLength({ min: 3 }),
    body('email').isEmail(),
    body('password').isLength({ min: 5 })
    
] ,async(req,res)=>{
  //if there are any errors it sends bad request 400
    const errors = validationResult(req);
    if (!errors.isEmpty()) {
      return res.status(400).json({ errors: errors.array() });
    }
    //check wether user exists with this email already
    try{
let user = await User.findOne({email: req.body.email});
if(user){

  return res.status(400).json({error: 'sorry user with this email already exists'})
}

const salt = await bcrypt.genSalt(10);
const secPass = await bcrypt.hash(req.body.password, salt) 

    user = await User.create({
        name: req.body.name,
        email: req.body.email,
        password: secPass
      })
      //this is for understanding purpose of other code
    //   .then(user => res.json(user))
    //   .catch(err =>{console.log(err)
    // res.json({error: 'email already exists', message: err.message})});
    res.json(user)
    } 
catch (error){
console.error(error.message);
res.status(500).send('some error occured')
}
})

module.exports = router

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