title: How to check if a string is already hashed in Node.js using crypto
body: <p>I am developing an application in which users are allowed o change their passwords.</p>
  
  <p>I am using Node.js with <code>mongoose</code> and <code>crypto</code>.</p>
  
  <p>In order to generate hashes for the passwords, I've hooked into model's pre('save') event. So basically when you use this:</p>
  
  <pre><code>var user = new User({password: '123'});
  user.save(); // the password will be encrypted automatically
  </code></pre>
  
  <p>Having the ability to change the password, I need to find a way if the user has actually changed the password or modified any other fields. Example:</p>
  
  <pre><code>var user = User.findById('1234567', function(error, user){
       user.name = 'Hello';
       user.save(); // this will hash the password again, although it is not necessary
  })
  </code></pre>
  
  <p>I am using Node.js's module called <code>crypto</code> to generate hash for passwords:</p>
  
  <pre><code>crypto.pbkdf2(password, salt, 5000, 512, 'sha512', function(error, buffer){
  
          this.mixins.callback.call(callback, [error, buffer.toString('base64')]);
  
  }.bind(this));
  </code></pre>
  
  <p><strong>Is there a way to check if the <code>password</code> is already a hashed?</strong><br>
  If not, I will generate the hash again.</p>
  
  <p>Thanks</p>