How to use the genSaltAsync function from bcrypt-nodejs

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

40
41
42
43
44
45
46
47
48
49

// normalize email address
self.set('email', self.get('email').toLowerCase().trim());

// salt and hash
return bcrypt.genSaltAsync(10).then(function(salt){
  return bcrypt.hashAsync(self.get('password'), salt, null).then(function(hash){
      self.set('password', hash);
      self.set('salt', salt);
      return;
fork icon24
star icon51
watch icon14

60
61
62
63
64
65
66
67
68
69
    });
};

// generates hash async
User.generateHash = function(password) {
  return bcrypt.genSaltAsync(8)
    .then(function(salt) {
      return bcrypt.hashAsync(password, salt, null);
    });
};
fork icon10
star icon0
watch icon8

24
25
26
27
28
29
30
31
32
33
comparePassword: function(attempted) {
  return bcrypt.compareAsync(attempted, this.get('password'));
},

generatePassword: function(password) {
  return bcrypt.genSaltAsync(null)
    .then(salt => {
      this.set('salt', salt);
      return bcrypt.hashAsync(password, salt, null);
    });
fork icon4
star icon0
watch icon5

1
2
3
4
5
6
7
8
9
10
var bBird = require("bluebird");
var bcrypt = bBird.promisifyAll(require('bcrypt-nodejs'));

var instanceMethods = {};
instanceMethods.hashPassword = function (newUser) {
  return bcrypt.genSaltAsync(10)
  .then(function (salt) {
    return bcrypt.hashAsync(newUser.password, salt, null);
  })
  .then(function (hash) {
fork icon3
star icon0
watch icon2

54
55
56
57
58
59
60
61
62
63
};

// generates hash async
User.generateHash = function(password) {
  // Use a work factor of 12 for hashing
  return bcrypt.genSaltAsync(12)
    .then(function(salt) {
      return bcrypt.hashAsync(password, salt, null)
      .then(function (passHash) {
        console.log('Salt:', salt, 'Passhash:', passHash);
fork icon3
star icon0
watch icon2

83
84
85
86
87
88
89
90
91
92
if (!member.changed('password')) {
  return sequelize.Promise.reject("not modified");
}

// bcrypt가 async이기 때문에 promise
return bcrypt.genSaltAsync(SALT_FACTOR).then(function(salt) {
  return bcrypt.hashAsync(member.password, salt, null);
}).then(function(hash) {
  member.setDataValue('password', hash);
}).catch(function(err) {
fork icon1
star icon4
watch icon7