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

377
Views
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 answers
Answer question

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 Report

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 Report
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!