Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function createUser(err) {
if (err) throw err;
bcrypt.genSalt(10, function(err, salt) {
if (err) throw err;
bcrypt.hash(app_tests.testuser_pass, salt, function() {}, function(err, hash) {
if (err) throw new Error(err);
app_tests.db_users.insert({ // add test user
email: app_tests.testuser_email,
password: hash
}, function(err, user) {
app_tests.testuser = user;
console.log('[DB: testuser added]');
this(err);
}.bind(this));
}.bind(this));
}.bind(this));
},
return new Promise((resolve, reject) => {
if (typeof password !== 'string') {
return reject(new Error('you must provide a string to encrypt'));
}
if (password.length < 6) {
return reject(new Error('minimum password string is 6 characters'));
}
if (henri.isTest) {
rounds = 10;
}
bcrypt.genSalt(rounds, (err, salt) => {
if (err) {
return reject(err);
}
bcrypt.hash(password, salt, null, (err, hash) => {
if (err) {
return reject(err);
}
return resolve(hash);
});
});
});
}
const hashPassword = (password: string, callBack: (error: Error, hash: string) => void) => {
bcrypt.genSalt(10, (err, salt) => {
if (err) {
return callBack(err, undefined);
}
bcrypt.hash(password, salt, undefined, (err: Error, hash) => {
if (err) {
return callBack(err, undefined);
}
callBack(undefined, hash);
});
});
};
beforeCreate: function (user, cb) {
delete user.password_confirmation;
bcrypt.genSalt(10, function (err, salt) {
bcrypt.hash(user.password, salt, function () {
}, function (err, hash) {
user.password = hash;
cb(null, user);
});
});
}
};
userSchema.pre('save', function(next) {
var user = this;
if (!user.isModified('password')) return next();
bcrypt.genSalt(10, function(err, salt) {
if (err) return next(err);
bcrypt.hash(user.password, salt, null, function(err, hash) {
if (err) return next(err);
user.password = hash;
next();
});
});
});