async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, (err) => { if (err) { return console.log(err); } console.log('DB populated'); });
// The hashes will be different since a salt is used to create unique tokens // You can use bcrypt.compare() to see if the original value is equal to salted token function hashIt(key) { return bcrypt.hashSync(key, SALT_ROUNDS); }
// hash user password before saving into database UserSchema.pre('save', function (next) { this.password = bcrypt.hashSync(this.password, saltRounds); next(); });
knex(table).insert( users.map( ({ name, email, password }) => ({ id: uuid(), name, email, email_confirmed: true, password_hash: bcrypt.hashSync(password, 10), }) ) )
static createUser(user) { return this.getUserByEmail(user.email) .then((resp)=>{ if (!resp.length) { const rounds = 10; const hash = bcrypt.hashSync(user.password, rounds); return DB.insertItem(tableName,{...user,password: hash}); } else { return console.log('Error: There is already a user with the email:', user.email); } }).catch(error=> console.log('Error Inserting User:', error)); }
userSchema.pre('save', function callback(next) { if (this.password) { const salt = bcrypt.genSaltSync(10); this.password = bcrypt.hashSync(this.password, salt); } next(); });
// bcrypt has async but we are using sync here for the example const hashPassword = (password, cb) => { const hash = bcrypt.hashSync(password, 16) cb(hash) }
UsersSchema.pre("save", function(next) { if (this.isModified("password") || this.isNew()) { this.password = bcrtypt.hashSync(this.password, 12); } next(); });
async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, (err) => { if (err) { return console.log(err); } console.log('DB populated'); });
async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, err => { if(err) { return console.log(err); } console.log('DB populated'); });
async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, (err) => { if (err) { return console.log(err); } console.log('DB populated'); });
async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, (err) => { if (err) { return console.log(err); } console.log('DB populated'); });
async.forEach(users, (user, callback) => { usersDb.put(user.username, { hash: bcrypt.hashSync(user.password, 8) }, callback); }, (err) => { if (err) { return console.log(err); } console.log('DB populated'); });
userSchema.pre('save', function callback(next) { if (this.password) { const salt = bcrypt.genSaltSync(10); this.password = bcrypt.hashSync(this.password, salt); } next(); });
// cluster.isWorker === true const hashPassword = (password, cb) => { const hash = bcrypt.hashSync(password, 16) // bcrypt has async but we are using sync here for the example cb(hash) }