Skip to content

Instantly share code, notes, and snippets.

@tysonnero
Created August 19, 2014 15:20
Show Gist options
  • Save tysonnero/e487ff61ac522976f3d8 to your computer and use it in GitHub Desktop.
Save tysonnero/e487ff61ac522976f3d8 to your computer and use it in GitHub Desktop.
UserSchema Pre-Validate Method
// Check password strength using OWASP module
UserSchema
.pre('validate', function (next) {
// Set options
owasp.config(config.password);
var result = owasp.test(this.password);
if (result.errors.length) {
// Join all errors in the array so only one error is returned
var error = result.errors.join(' ');
this.invalidate('password', error);
}
next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment