Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose password validation #4157

Merged
merged 3 commits into from
Sep 21, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions fields/types/password/PasswordType.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,37 +162,44 @@ password.prototype.compare = function (item, candidate, callback) {
* Asynchronously confirms that the provided password is valid
*/
password.prototype.validateInput = function (data, callback) {
var detail = '';
var result = true;
var min = this.options.min;
var max = this.options.max || 72;
var max = this.options.max;
var complexity = this.options.complexity;
var confirmValue = this.getValueFromData(data, '_confirm');
var passwordValue = this.getValueFromData(data);
if (confirmValue !== undefined
&& passwordValue !== confirmValue) {

var validation = validate(passwordValue, confirmValue, min, max, complexity);

utils.defer(callback, validation.result, validation.detail);
};

var validate = password.validate = function (pass, confirm, min, max, complexity) {
var detail = '';
var result = true;
max = max || 72;
if (confirm !== undefined
&& pass !== confirm) {
detail = 'passwords must match\n';
}

if (min && typeof passwordValue === 'string' && passwordValue.length < min) {
if (min && typeof pass === 'string' && pass.length < min) {
detail += 'password must be longer than ' + min + ' characters\n';
}

if (max && typeof passwordValue === 'string' && passwordValue.length > max) {
if (max && typeof pass === 'string' && pass.length > max) {
detail += 'password must not be longer than ' + max + ' characters\n';
}

for (var prop in complexity) {
if (complexity[prop] && typeof passwordValue === 'string') {
var complexityCheck = (regexChunk[prop]).test(passwordValue);
if (complexity[prop] && typeof pass === 'string') {
var complexityCheck = (regexChunk[prop]).test(pass);
if (!complexityCheck) {
detail += detailMsg[prop] + '\n';
}
}
}
result = detail.length === 0;

utils.defer(callback, result, detail);
return { result, detail };
};

/**
Expand Down