Skip to content

Instantly share code, notes, and snippets.

@deedubs
Forked from shiawuen/index.js
Created January 19, 2012 19:04
Show Gist options
  • Save deedubs/1641857 to your computer and use it in GitHub Desktop.
Save deedubs/1641857 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);
this.set('passwordHash',undefined);
this.set('passwordConfirm',undefined);
// 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