Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

380
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda