Skip to content

Instantly share code, notes, and snippets.

@artcommacode
Created July 31, 2014 16:05
Show Gist options
  • Save artcommacode/ceff41f2fb9ba7321730 to your computer and use it in GitHub Desktop.
Save artcommacode/ceff41f2fb9ba7321730 to your computer and use it in GitHub Desktop.
sUser.pre('save', co(function *(next) {
if (!this.isModified('password')) return next();
this.password = yield this.encryptPassword(this.password)
return next()
}))
sUser.methods.encryptPassword = function *(password) {
var salt = yield thunkify(bcrypt.genSalt)(10)
return yield thunkify(bcrypt.hash)(password, salt, null)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment