Password requirement custom message (#5399)

* Added validationError(custom message) for Password requirement fail

* Changed validationError from valodationError in README.md
This commit is contained in:
pateldharad
2019-02-28 16:17:31 -05:00
committed by Arthur Cinader
parent 1e7cc7ba00
commit 6eaefd95ae
3 changed files with 24 additions and 7 deletions

View File

@@ -611,8 +611,17 @@ RestWrite.prototype._validatePasswordPolicy = function() {
RestWrite.prototype._validatePasswordRequirements = function() {
// check if the password conforms to the defined password policy if configured
const policyError =
'Password does not meet the Password Policy requirements.';
// If we specified a custom error in our configuration use it.
// Example: "Passwords must include a Capital Letter, Lowercase Letter, and a number."
//
// This is especially useful on the generic "password reset" page,
// as it allows the programmer to communicate specific requirements instead of:
// a. making the user guess whats wrong
// b. making a custom password reset page that shows the requirements
const policyError = this.config.passwordPolicy.validationError
? this.config.passwordPolicy.validationError
: 'Password does not meet the Password Policy requirements.';
const containsUsernameError = 'Password cannot contain your username.';
// check whether the password meets the password strength requirements
if (
@@ -632,7 +641,7 @@ RestWrite.prototype._validatePasswordRequirements = function() {
// username is not passed during password reset
if (this.data.password.indexOf(this.data.username) >= 0)
return Promise.reject(
new Parse.Error(Parse.Error.VALIDATION_ERROR, policyError)
new Parse.Error(Parse.Error.VALIDATION_ERROR, containsUsernameError)
);
} else {
// retrieve the User object using objectId during password reset
@@ -644,7 +653,10 @@ RestWrite.prototype._validatePasswordRequirements = function() {
}
if (this.data.password.indexOf(results[0].username) >= 0)
return Promise.reject(
new Parse.Error(Parse.Error.VALIDATION_ERROR, policyError)
new Parse.Error(
Parse.Error.VALIDATION_ERROR,
containsUsernameError
)
);
return Promise.resolve();
});