description and source-codetest = function (password) {
// create an object to store the test results
var result = {
errors : [],
failedTests : [],
passedTests : [],
requiredTestErrors : [],
optionalTestErrors : [],
isPassphrase : false,
strong : true,
optionalTestsPassed : 0,
};
// Always submit the password/passphrase to the required tests
var i = 0;
this.tests.required.forEach(function(test) {
var err = test(password);
if (typeof err === 'string') {
result.strong = false;
result.errors.push(err);
result.requiredTestErrors.push(err);
result.failedTests.push(i);
} else {
result.passedTests.push(i);
}
i++;
});
// If configured to allow passphrases, and if the password is of a
// sufficient length to consider it a passphrase, exempt it from the
// optional tests.
if (
this.configs.allowPassphrases === true &&
password.length >= this.configs.minPhraseLength
) {
result.isPassphrase = true;
}
if (!result.isPassphrase) {
var j = this.tests.required.length;
this.tests.optional.forEach(function(test) {
var err = test(password);
if (typeof err === 'string') {
result.errors.push(err);
result.optionalTestErrors.push(err);
result.failedTests.push(j);
} else {
result.optionalTestsPassed++;
result.passedTests.push(j);
}
j++;
});
}
// If the password is not a passphrase, assert that it has passed a
// sufficient number of the optional tests, per the configuration
if (
!result.isPassphrase &&
result.optionalTestsPassed < this.configs.minOptionalTestsToPass
) {
result.strong = false;
}
// return the result
return result;
}