Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _passwordMinStrength=2;
- var _passwordMinLength=8;
- var _passwordStrengthRules = [
- {passwordStrength: 4, minLength: 8, charClassCount: 4},
- {passwordStrength: 3, minLength: 8, charClassCount: 3},
- {passwordStrength: 2, minLength: _passwordMinLength, charClassCount: 2},
- {passwordStrength: 1, minLength: _passwordMinLength, charClassCount: 1}
- ];
- function calculatePasswordStrength(password) {
- var selectedStrength = 0;
- for (var i=0; i<_passwordStrengthRules.length; i++) {
- var minLength = _passwordStrengthRules[i].minLength;
- var charClassCount = _passwordStrengthRules[i].charClassCount;
- var classCount = 0;
- if(password.match(jQuery("#passwordPattern").val())){
- classCount+=2;
- if ((password.match(/[a-z�����ęš]/g) || []).length >= 1) {
- classCount += 1;
- }
- if ((password.match(/[@!#$%^&*/?><]/g) || []).length >= 1) {
- classCount += 1;
- }
- }
- if (classCount >= charClassCount) {
- if(charClassCount>=3){
- if(password.length>=_passwordStrengthRules[i].minLength) {
- selectedStrength = _passwordStrengthRules[i].passwordStrength;
- break;
- }
- }else {
- selectedStrength = _passwordStrengthRules[i].passwordStrength;
- break;
- }
- }
- }
- return selectedStrength;
- }
- function checkPasswordStrength(passwordInput, passwordInfo, errorSpan,
- infoSpan, leftToRight) {
- var password = $(passwordInput).val();
- var calculatedStrength = calculatePasswordStrength(password);
- //info about safe password
- if (calculatedStrength == 4) {
- $(infoSpan).removeClass('hidden');
- } else{
- $(infoSpan).addClass('hidden');
- }
- //error about weak password
- if(calculatedStrength < _passwordMinStrength){
- var errmsg=$('#wrongPasswordSyntaxMsg').val();
- $(errorSpan).html(errmsg);
- } else{
- $(errorSpan).html('');
- }
- if (!$(passwordInfo).children().length && $(passwordInput).val().length >= _passwordMinLength)
- $(passwordInfo).append('<span></span><span></span><span></span><span></span>');
- if (leftToRight == true) {
- $(passwordInfo).children().each(function(index, item) {
- if (index < calculatedStrength)
- $(item).css("display", "block");
- else
- $(item).css("display", "none");
- });
- } else {
- $(passwordInfo).children().reverse().each(function(index, item) {
- if (index < calculatedStrength)
- $(item).css("visibility", "visible");
- else
- $(item).css("visibility", "hidden");
- });
- }
- return calculatedStrength;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement