title: Hash, salt and save password in Node/Express
body: <p>I have required the Crypto module in Node's standard library. 
  I have this POST route which handle a registration form:</p>
  
  <pre><code>app.post('/superadmin/add-account', function(req, res) {
  
    // Shorthand variable
    var doc = req.body;
  
    crypto.randomBytes(32, function(err, buf) {
  
      if (err) throw err;
  
      // Sanitise and transform user input
      ... 
  
      // Validate user input
      ... 
  
      var errors = validator.getErrors();
  
      // Generate new object data
      doc.salt = buf; 
      doc.pass = doc.salt + 'justForNow';
  
      console.log(doc);
  </code></pre>
  
  <p>When i output the doc (req.body) now i get some values that seems strange to me...
  The buf outputted in the console is mostly made up of charachter that resemble a box with a question mark inside. Is this correct? But when i save the buf to doc.salt and output this i get something completly else... "Slowbuffer ae be C5 A3 E3.... and so on"</p>
  
  <p><strong>Q1:</strong> Do I have to do something special (parse it to something?) with the salt generated by crypto.randomBytes() before i use it concatenation with a string or save it? </p>
  
  <p><strong>Q2:</strong> The crypto.randomBytes() function exist in async and sync version. Im using the async version but i really dont know why? =P I thought async callbaks was mostly used when handling I/O operations that might take time... Or am I using a callback version of this function because it is actually a complicated process that might take some time and lock the system for som MS if I use the sync version?</p>
  
  <p><strong>Q3:</strong> I'm not there yet, but I will continue this code with using The Crypto module's hash function for hashing the salt + password and save it to DB. I know i have to create a var like this: </p>
  
  <pre><code>var sha256 = crypto.createHash('sha256'); 
  </code></pre>
  
  <p>But i dont understand how i now use this.  </p>