1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-01 16:51:11 +03:00

fixed password strength

-implemented rules for length, and lowercase, uppercase, number and symbol subsets
-made it user configurable in local_config.js
-set defaults to 8 character length and true for all character sets required
This commit is contained in:
John Mitchell 2015-05-15 14:14:55 -04:00
parent a84aed63c9
commit 50059f92c5
3 changed files with 105 additions and 6 deletions

View File

@ -21,12 +21,12 @@
debug_mode: false, // Enable console logging messages
password_strength: 45, // User password strength. Integer between 0 and 100, 100 being impossibly strong.
// This value controls progress bar colors:
// 0 to password_strength - 15 = red;
// password_strength - 15 to password_strength = yellow
// > password_strength = green
// It also controls password validation. Passwords are rejected if the score is not > password_strength.
password_length: 8, // Minimum user password length. Set to 0 to not set a limit
password_hasLowercase: true, // require a lowercase letter in the password
password_hasUppercase: true, // require an uppercase letter in the password
password_hasNumber: true, // require a number in the password
password_hasSymbol: true, // require one of these symbols to be
// in the password: -!$%^&*()_+|~=`{}[]:";'<>?,./
session_timeout: 1800, // Number of seconds before an inactive session is automatically timed out and forced to log in again.
// Separate from time out value set in API.

View File

@ -60,6 +60,64 @@ angular.module('AWDirectives', ['RestServices', 'Utilities', 'AuthService', 'Job
};
})
// chkPass
//
// Enables use of js/shared/pwdmeter.js to check strengh of passwords.
// See controllers/Users.js for example.
//
.directive('chkPass', [ function() {
return {
require: 'ngModel',
link: function(scope, elm, attrs, ctrl) {
$(elm).keyup(function() {
var validity = true;
if (elm.val()) {
if ($AnsibleConfig.password_length) {
validity = (ctrl.$modelValue.length >= $AnsibleConfig.password_length);
ctrl.$setValidity('password_length', validity);
}
if ($AnsibleConfig.password_hasLowercase) {
validity = (/[a-z]/.test(ctrl.$modelValue));
ctrl.$setValidity('hasLowercase', validity);
}
if ($AnsibleConfig.password_hasUppercase) {
validity = (/[A-Z]/.test(ctrl.$modelValue));
ctrl.$setValidity('hasUppercase', validity);
}
if ($AnsibleConfig.password_hasNumber) {
validity = (/[0-9]/.test(ctrl.$modelValue));
ctrl.$setValidity('hasNumber', validity);
}
if ($AnsibleConfig.password_hasSymbol) {
validity = (/[$-/:-?{-~!"^_`\[\]]/.test(ctrl.$modelValue));
ctrl.$setValidity('hasSymbol', validity);
}
} else {
validity = true;
if ($AnsibleConfig.password_length) {
ctrl.$setValidity('password_length', validity);
}
if ($AnsibleConfig.password_hasLowercase) {
ctrl.$setValidity('hasLowercase', validity);
}
if ($AnsibleConfig.password_hasUppercase) {
ctrl.$setValidity('hasUppercase', validity);
}
if ($AnsibleConfig.password_hasNumber) {
ctrl.$setValidity('hasNumber', validity);
}
if ($AnsibleConfig.password_hasSymbol) {
ctrl.$setValidity('hasSymbol', validity);
}
}
if (!scope.$$phase) {
scope.$digest();
}
});
}
};
}])
.directive('surveyCheckboxes', function(){
return {

View File

@ -397,6 +397,23 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
scope[form.name + '_form'][fld].$setPristine();
scope[form.name + '_form'][fld].$setValidity('apiError', true);
}
if (f.chkPass && scope[form.name + '_form'][fld]) {
if ($AnsibleConfig.password_length) {
scope[form.name + '_form'][fld].$setValidity('password_length', true);
}
if ($AnsibleConfig.password_hasLowercase) {
scope[form.name + '_form'][fld].$setValidity('hasLowercase', true);
}
if ($AnsibleConfig.password_hasUppercase) {
scope[form.name + '_form'][fld].$setValidity('hasUppercase', true);
}
if ($AnsibleConfig.password_hasNumber) {
scope[form.name + '_form'][fld].$setValidity('hasNumber', true);
}
if ($AnsibleConfig.password_hasSymbol) {
scope[form.name + '_form'][fld].$setValidity('hasSymbol', true);
}
}
if (f.awPassMatch && scope[form.name + '_form'][fld]) {
scope[form.name + '_form'][fld].$setValidity('awpassmatch', true);
}
@ -899,6 +916,7 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += "class='form-control";
html += (field['class']) ? " " + this.attr(field, 'class') : "";
html += "' ";
html += (field.chkPass) ? "chk-pass " : "";
html += (field.placeholder) ? this.attr(field, 'placeholder') : "";
html += (options.mode === 'edit' && field.editRequired) ? "required " : "";
@ -965,6 +983,29 @@ angular.module('FormGenerator', [GeneratorHelpers.name, 'Utilities', listGenerat
html += "<div class='error' id='" + this.form.name + "-" + fld + "-url-error' ng-show='" + this.form.name + "_form." + fld +
".$error.awvalidurl'>\nPlease enter a URL that begins with ssh, http or https. The URL may not contain the '@' character.\n</div>\n";
}
if (field.chkPass) {
// password strength
if ($AnsibleConfig.password_length) {
html += "<div class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld +
".$error.password_length\">Your password must be " + $AnsibleConfig.password_length + " characters long.</div>\n";
}
if ($AnsibleConfig.password_hasLowercase) {
html += "<div class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld +
".$error.hasLowercase\">Your password must contain a lowercase letter.</div>\n";
}
if ($AnsibleConfig.password_hasUppercase) {
html += "<div class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld +
".$error.hasUppercase\">Your password must contain an uppercase letter.</div>\n";
}
if ($AnsibleConfig.password_hasNumber) {
html += "<div class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld +
".$error.hasNumber\">Your password must contain a number.</div>\n";
}
if ($AnsibleConfig.password_hasSymbol) {
html += "<div class=\"error\" ng-show=\"" + this.form.name + '_form.' + fld +
".$error.hasSymbol\">Your password must contain one of the following characters: -!$%^&*()_+|~=`{}\[\]:\";\'<>?,.\/.</div>\n";
}
}
html += "<div class='error api-error' id='" + this.form.name + "-" + fld + "-api-error' ng-bind='" + fld + "_api_error'>\n</div>\n";