How to use the bcrypt.gen_salt function in bcrypt

To help you get started, we’ve selected a few bcrypt examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github powmedia / mongoose-plugins / lib / authenticator.js View on Github external
function encryptPassword(password, callback) {
        bcrypt.gen_salt(workFactor, function(err, salt) {
            if (err) callback(err);
            
            bcrypt.encrypt(password, salt, function(err, hashedPassword) {
                if (err) callback(err);
                
                callback(null, hashedPassword);
            });
        });
    }
github kevbook / Base-Node.js-App / lib / authx.js View on Github external
User.methods.setPassword = function setPassword(password, callback) {
  var user = this;
  bcrypt.gen_salt(10, function(err, salt) {
    bcrypt.encrypt(password, salt, function(err, hash) {
      if (err) {
        callback(new Error('Failed to encrypt password.'));
      }
      else {
        user.password = hash;
        callback(null, user);
      }
    });
  });
};
github tdryer / express-forum / app.js View on Github external
success: function (form) {
      bcrypt.gen_salt(12, function (err, salt) {
        bcrypt.encrypt(form.data.password, salt, function (err, hash) {
          db.run('INSERT INTO user (username, password_hash) values (?, ?)', 
                 form.data.username, hash, function (err) {
            req.flash('info', 'Account created. Login to continue.');
            res.redirect('/login');
          });
        });
      });
    },
    other: function (form) {