title: Data and salt arguments required error (authorization)
body: <p>I'm a beginner in NodeJS and I've tried to make an authentication form using NodeJS + express. I want to make a validation for my password (when "confirmpassword" is different than "password" it should return nothing. Unfortunately, I keep getting "data and salt arguments required". I tried in different ways, to put some conditions, but I keep getting this error. Any ideas how I should make it work?
  Here is the file user.js:</p>
  
  <pre><code>const pool = require('./pool');
  const bcrypt = require('bcrypt');
  
  
  function User() {};
  
  User.prototype = {
  
  find : function(user = null, callback)
  {
      if(user) {     
          var field = Number.isInteger(user) ? 'id' : 'username';
      }
      let sql = `SELECT * FROM users WHERE ${field} = ?`;
  
      pool.query(sql, user, function(err, result) {
          if(err) 
              throw err
          if(result.length) {
              callback(result[0]);
          }else {
              callback(null);
          }
      });
  },
  
  create : function(body, callback) 
  {
      var pwd = body.password;
      var cpwd = body.confirmpassword;
  
      // here i hash the pass
      body.password = bcrypt.hashSync(pwd,10);
      body.confirmpassword = bcrypt.hashSync(cpwd, 10);
  
      if (body.password != body.confirmpassword){
          callback(null);
      }
      else {
  
      var bind = [];
  
      for(prop in body){
          bind.push(body[prop]);
      }
  
      let sql = `INSERT INTO users(username, fullname, password) VALUES (?, ?, ?)`;
  
      pool.query(sql, bind, function(err, result) {
          if(err) throw err;     
          callback(result.insertId);
      });
      }
  },
  
  login : function(username, password, callback)
  {
      this.find(username, function(user) {
          if(user) {
              if(bcrypt.compareSync(password, user.password)) {       
                  callback(user);
                  return;
              }  
          }
          callback(null);
      });    
  }
  
  }
  module.exports = User;
  </code></pre>
  
  <p>And the file pages.js:</p>
  
  <pre><code>const express = require('express');
  const User = require('../core/user');
  const router = express.Router();
  
  const user = new User();
  
  router.get('/', (req, res, next) =&gt; {
      let user = req.session.user;
      if(user) {
          res.redirect('/home');
          return;
      }
      res.render('index', {title:"My application"});
  })
  
  router.get('/home', (req, res, next) =&gt; {
      let user = req.session.user;
      if(user) {
          res.render('home', {opp:req.session.opp, name:user.fullname});
          return;
      }
      res.redirect('/');
  });
  
  
  router.post('/login', (req, res, next) =&gt; {
      user.login(req.body.username, req.body.password, function(result) {
          if(result) {           
              req.session.user = result;
              req.session.opp = 1;          
              res.redirect('/home');
          }else {        
              res.send('Username/Password incorrect!');
          }
      })
  
  });
  
  router.post('/register', (req, res, next) =&gt; {
      let userInput = {
          username: req.body.username,
          fullname: req.body.fullname,
          password: req.body.password
      };
  
      user.create(userInput, function(lastId) {
          if(lastId) {
              user.find(lastId, function(result) {
                  req.session.user = result;
                  req.session.opp = 1;
                  res.redirect('/home');
              });
          }else {
              console.log('Error creating a new user ...');
          }
      });
  });
  
  router.get('/logout', (req, res, next) =&gt; {
      if(req.session.user) {
          req.session.destroy(function() {
              res.redirect('/');
          });
      }
  });
  module.exports = router;
  </code></pre>