title: bcrypt-nodejs.compare always returns false
body: <p>I am setting up a login using node.js, bcrypt, sequelize, and passport and I've followed the documentation online but for some reason the .compare function always returns false even when I know the passwords match.</p>
  
  <p>In my model I added a beforCreate hook to encrypt the password:</p>
  
  <pre><code>beforeUpdate: function(user, options, fn) {
      encryptPassword(user, options, fn);
  }
  </code></pre>
  
  <p>encryptPassword function:</p>
  
  <pre><code>encryptPassword = function(user, options, fn) {
      if (!user.changed('password'))
          return fn();
  
      bcrypt.hash(this.password, null, null, function(err, hash) {
          if (err) return fn(err);
          user.password = hash;
          fn();
      });
  }
  </code></pre>
  
  <p>My controller where I create the user:</p>
  
  <pre><code>User
      .create({
          username: req.body.username,
          password: req.body.password
      })
      .then(function() {
          res.json({
              message: 'New beer drinker added to the locker room!'
          });
      });
  </code></pre>
  
  <p>That works great, the user is stored in my DB with the hashed password.</p>
  
  <p>Now I try to log the user in using passport</p>
  
  <pre><code>passport.use(new BasicStrategy(
      function(username, password, callback) {
          User
              .find({
                  where: {
                      username: username
                  }
              })
              .then(function(user) {
                  // No user found with that username
                  if(!user) return callback(null, false);
  
                  // Make sure the password is correct
                  user.verifyPassword(password, function(err, isMatch) {
                      if(err) return callback(err);
  
                      // Password did not match
                      if(!isMatch) return callback(null, false);
  
                      // Success
                      return callback(null, user);
                  });
              })
              .catch(function(err) {
                  return callback(err);
              });
      }
  ));
  </code></pre>
  
  <p>This process calls user.verifyPassword which is an instanceMethod of my user model.</p>
  
  <pre><code>verifyPassword: function(password, callback) {
      bcrypt.compare(password, this.password, callback);
  }
  </code></pre>
  
  <p>However the callback is always false regardless of if the passwords match or not. Does anyone have any ideas what I'm doing wrong? I tried to switch to bcrypt but I couldn't get it to install because node-gyp rebuild always fails complaining it can't find the env variable for python which I've installed. Plus I don't want to have a huge pain in the ass trying to get the server developers to set up a server with all of the dependencies and stuff of the normal bcrypt.</p>