ohif-viewer/Packages/active-entry/lib/checkPasswordStrength.js
Aysel Afsar e659f0f4b3 - Renamed validatePassword method, usePwstrength and useZxcvbn,
- Moved passwordOptions from settings.json to ActiveEntry configuration object
- Used zxcvbn rule set if showPasswordStrengthIndicator is true, used regular expression rule set if showPasswordStrengthIndicator is false
2016-02-04 17:53:01 -05:00

46 lines
1.9 KiB
JavaScript

passwordValidationSettings = {};
var ActiveEntryConfiguration;
Meteor.startup(function() {
ActiveEntryConfiguration = Session.get('Photonic.ActiveEntry');
var showPasswordStrengthIndicator = (ActiveEntryConfiguration && ActiveEntryConfiguration.passwordOptions && ActiveEntryConfiguration.passwordOptions.showPasswordStrengthIndicator || false);
passwordValidationSettings.requireStrongPasswords = (ActiveEntryConfiguration && ActiveEntryConfiguration.passwordOptions && ActiveEntryConfiguration.passwordOptions.requireStrongPasswords || false);
passwordValidationSettings.showPasswordStrengthIndicator = showPasswordStrengthIndicator;
passwordValidationSettings.pwstrengthOptions = {
common: {
minChar: 8,
zxcvbn: showPasswordStrengthIndicator
},
ui: {
showVerdictsInsideProgressBar: true,
showStatus: true
},
rules: {
activated: {
wordNotEmail: true,
wordTwoCharacterClasses: true,
wordRepetitions: true
}
}
};
});
// Check Password Strength: at least 8 characters in length and contain at least 1 uppercase, 1 lowercase and 1 number and 1 special character
checkPasswordStrength = function(password) {
var iszxcvbnActive = (ActiveEntryConfiguration && ActiveEntryConfiguration.passwordOptions && ActiveEntryConfiguration.passwordOptions.showPasswordStrengthIndicator || false);
if (iszxcvbnActive) {
// Check zxcvbn rule
var zxcvbnResult = zxcvbn(password);
if (zxcvbnResult.score > 2) {
return true;
}
} else{
// Apply validation rule
var result = password.search(/^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#$%^&*])[0-9a-zA-Z!@#$%^&*]{8,}$/i);
if (result > -1) {
return true;
}
}
return false;
};