Skip to content

Instantly share code, notes, and snippets.

@shiawuen
Created January 19, 2012 18:52
Show Gist options
  • Save shiawuen/1641813 to your computer and use it in GitHub Desktop.
Save shiawuen/1641813 to your computer and use it in GitHub Desktop.
var userSchema = new Schema({
email: String
, passwordHash: String
});
userSchema.pre('validate', function(next) {
if (this.password === this.passwordConfirm) {
this.set('passwordHash', hash(this.password);
// How do I prevent this.password and this.passwordConfirm
// to be save into DB?
}
next()
});
var User = db.model('User', userSchema);
var user = new User()
user.init({
email: '[email protected]'
, password: 'password'
, confirmPassword: 'password'
});
user.save(function(err) {
console.log(!!err ? 'error' : 'saved');
});
function hash(str) { return str+'hashed' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment