April 2020
Intermediate to advanced
716 pages
18h 55m
English
To add validation constraints to the actual password string that's selected by the end user, we need to add custom validation logic and associate it with the hashed_password field in the schema.
mern-skeleton/server/models/user.model.js:
UserSchema.path('hashed_password').validate(function(v) { if (this._password && this._password.length < 6) { this.invalidate('password', 'Password must be at least 6 characters.') } if (this.isNew && !this._password) { this.invalidate('password', 'Password is required') }}, null)
We will keep the password validation criteria simple in our application and ensure that a password value is provided and it has a length of at least six characters when a new user is created or an existing ...
Read now
Unlock full access