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

382
Vistas
for salt and hashing passwords i used Bcrypt method but its showing , error = new Error('data and salt arguments required');

for salt and hashing passwords i used Bcrypt method but its showing , error = new Error('data and salt arguments required'); i think my code have the problem please i need help please; eCommerce website is my project so ,i created signup form in user panel

*user.js

const userHelpers=require('../helpers/user-helpers')
 
router.get('/signup',(req,res)=>{
   res.render('user/signup')
})

router.post('/signup',(req,res)=>{
  userHelpers.doSignup(req.body).then((response)=>{
     console.log(response);
  })

user-helpers.js

var db=require('../config/connection')
 var collection=require('../config/collections')
 const bcrypt=require('bcrypt')

module.exports={
    doSignup:(userData)=>{
        return new Promise(async(resolve,reject)=>{
            // var salt =  await bcrypt.genSalt(10);
            userData.Password= await bcrypt.hash(userData.Password ,10)
                db.get().collection(collection.USER_COLLECTION).insertOne(userData).then((data)=>{

                    resolve(data) 
                });
                     
            });
          
    }

collection.js

module.exports={
    PRODUCT_COLLECTION:'product',
    USER_COLLECTION:'user'
}  

this is my code but the error shoing

error = new Error('data and salt arguments required');
                ^

Error: data and salt arguments required

how to fix the problem ..

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

0

According to the error you get, it looks like the function bcrypt.hash fails because userData.Password might not be set. Make sure that you get the userData.Password correctly with the request. If you use express you might not have a conversion to JSON so add a middleware to parse the data to JSON, like:

const express = require('express');
const app = express();

app.use(express.json());

app.post('/', function(request, response){
  console.log(request.body);      // your JSON
   response.send(request.body);    // echo the result back
});

app.listen(3000);

Take a look at these previous questions & answers:

  • Error: data and salt arguments required
  • How do I consume the JSON POST data in an Express application
about 4 years ago · Juan Pablo Isaza Denunciar

0

Thank you, I got the solution. The problem in the user-helpers.js.

user-helpers.js


    const bcrypt = require('bcrypt')
         
    module.exports={
        doSignup:(userData)=>{
            return new Promise (async(resolve,reject)=>{
          
            userData.password=await bcrypt.hash(userData.password,10)
                   
                      db.get().collection(collection.USER_COLLECTION).insertOne(userData).then((data)=>{
                        resolve(data) 
                        // console.log(userData.password)
                        // console.log(userData.email)                    
                    });
                    });
                 
         }
    ```
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