Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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);
});
});
}
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);
}
});
});
};
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) {