How to use the compareAsync function from bcrypt-nodejs

Find comprehensive JavaScript bcrypt-nodejs.compareAsync code examples handpicked from public code repositorys.

29
30
31
32
33
34
35
36
37
38
    beforeSave: hashPassword
  }
})

User.prototype.comparePassword = function (password) {
  return bcrypt.compareAsync(password, this.password)
}

User.associate = function (models) {
}
fork icon197
star icon506
watch icon37

56
57
58
59
60
61
62
63
64
65
User.verify = Promise.method(function(email, password){
  if (!email || !password) return null;
  return new User({email: email.toLowerCase().trim()})
    .fetch().then(function(user) {
      if(!user) return null;
      return bcrypt.compareAsync(password, user.get('password')).then(function(match){
        if(!match) return null;
        return user;
      });
    });
fork icon24
star icon51
watch icon14

68
69
70
71
72
73
74
75
76
    });
};

// checks password async with stored password
User.validPassword = function(password) {
  return bcrypt.compareAsync(password, this.passHash);
};

module.exports = User;
fork icon10
star icon0
watch icon8

17
18
19
20
21
22
23
24
25
26
        bcrypt.compare(password, hash, function(err, result) {
            callback(err, result);
        });
    }
    else {
        return bcrypt.compareAsync(password, hash);
    }
}

module.exports = {
fork icon4
star icon4
watch icon2

66
67
68
69
70
71
72
73
74
    });
};

// checks password async with stored password
User.validPassword = function(enteredPassword, passwordHash) {
  return bcrypt.compareAsync(enteredPassword, passwordHash);
};

module.exports = User;
fork icon3
star icon0
watch icon2

27
28
29
30
31
32
33
34
35
        beforeCreate: hashPassword
    }
});

User.prototype.comparePassword = function (password) {
    return bcrypt.compareAsync(password, this.password);
}

module.exports = User;
fork icon0
star icon1
watch icon1

16
17
18
19
20
21
22
23
24
25
}
if (rows.length === 0) {
  next(new Error('User does not exist'));
} else {
  var user = rows[0];
  bcrypt.compareAsync(password, user.password).then(result => {
    if (result) {
      var token = jwt.encode(user, 'secret');
      res.json({token: token});
    } else {
fork icon9
star icon0
watch icon1

20
21
22
23
24
25
26
27
28
29
    }
  });
},

comparePassword: function(attempted) {
  return bcrypt.compareAsync(attempted, this.get('password'));
},

generatePassword: function(password) {
  return bcrypt.genSaltAsync(null)
fork icon4
star icon0
watch icon5

14
15
16
17
18
19
20
21
22
23
    console.log('Error: ', err);
  });
};

instanceMethods.comparePassword = function (user, potentialUser) {
  return bcrypt.compareAsync(potentialUser.password, user.password)
  .then(function (matched){
    if(!matched) return bBird.resolve(false);
    else return bBird.resolve(user);
  });
fork icon3
star icon0
watch icon2

65
66
67
68
69
70
71
72
73
74
// data - [REQUIRED] - data to compare.
//  encrypted - [REQUIRED] - data to be compared to.
//  callback - [REQUIRED] - a callback to be fired once the data has been compared.
//   error - First parameter to the callback detailing any errors.
//   result - Second parameter to the callback providing whether the data and encrypted forms match [true | false].
bcrypt.compareAsync(candidatePassword, self.password).then(function(isMatch) {
  return cb(null, isMatch);
}).catch(function(err) {
  if (err) {
    return cb(err);
fork icon1
star icon4
watch icon7

5
6
7
8
9
10
11
12
13
14
var autoLogin = function(username,password,user){return user;};

var login = {};

login.local = function(username,password,user){
  return bcrypt.compareAsync(password,user.get('password'));
};

login.guest = autoLogin;
login.github = autoLogin;
fork icon0
star icon10
watch icon2

23
24
25
26
27
28
29
30
31

  if (!user) {
    throw new Error('user not found');
  }
  this.user = user.dataValues;
  return bcrypt.compareAsync(password, this.user.password);
})
.then(function (isVerified) {
  if(isVerified) {
fork icon0
star icon0
watch icon1

+ 4 other calls in file

43
44
45
46
47
48
49
50
51
        }
        resolve(rows[0])
      })
    })
  },
  comparePassword: async (password, hashPassword) => bcrypt.compareAsync(password, hashPassword)
}

module.exports = User
fork icon0
star icon0
watch icon1