Click here to Skip to main content
15,567,415 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
jQuery....jquery.pstrength-min.1.2.js file.... password strength

can we plz explain this code i can't understand how it is working.....


JavaScript
(function(A) {
    A.extend(A.fn, { pstrength: function(B) {
        var B = A.extend({ verdects: ["Very weak", "Weak", "Medium", "Strong", "Very strong"], colors: ["#f00", "#c06", "#f60", "#3c0", "#3f0"], scores: [10, 15, 30, 40], common: ["password", "sex", "god", "123456", "123", "liverpool", "letmein", "qwerty", "monkey", "111111111", "22222222", "333333333", "44444444"], minchar: 6 }, B);
        return this.each(function() { var C = A(this).attr("id"); A(this).after("<div class=\"pstrength-minchar\" id=\"" + C + "_minchar\">Minimum number of characters is " + B.minchar + "</div>"); A(this).after("<div class=\"pstrength-info\" id=\"" + C + "_text\"></div>"); A(this).after("<div class=\"pstrength-bar\" id=\"" + C + "_bar\" style=\"border: 1px solid white; font-size: 1px; height: 5px; width: 0px;\"></div>"); A(this).keyup(function() { A.fn.runPassword(A(this).val(), C, B) }) })
    }, runPassword: function(D, F, C) { nPerc = A.fn.checkPassword(D, C); var B = "#" + F + "_bar"; var E = "#" + F + "_text"; if (nPerc == -200) { strColor = "#f00"; strText = "Unsafe password word!"; A(B).css({ width: "0%" }) } else { if (nPerc < 0 && nPerc > -199) { strColor = "#008080"; strText = "Too short"; A(B).css({ width: "5%" }) } else { if (nPerc <= C.scores[0]) { strColor = C.colors[0]; strText = C.verdects[0]; A(B).css({ width: "10%" }) } else { if (nPerc > C.scores[0] && nPerc <= C.scores[1]) { strColor = C.colors[1]; strText = C.verdects[1]; A(B).css({ width: "16%" }) } else { if (nPerc > C.scores[1] && nPerc <= C.scores[2]) { strColor = C.colors[2]; strText = C.verdects[2]; A(B).css({ width: "18%" }) } else { if (nPerc > C.scores[2] && nPerc <= C.scores[3]) { strColor = C.colors[3]; strText = C.verdects[3]; A(B).css({ width: "20%" }) } else { strColor = C.colors[4]; strText = C.verdects[4]; A(B).css({ width: "22%" }) } } } } } } A(B).css({ backgroundColor: strColor }); A(E).html("<span style='color: " + strColor + ";'>" + strText + "</span>") }, checkPassword: function(C, B) { var F = 0; var E = B.verdects[0]; if (C.length < B.minchar) { F = (F - 100) } else { if (C.length >= B.minchar && C.length <= (B.minchar + 2)) { F = (F + 6) } else { if (C.length >= (B.minchar + 3) && C.length <= (B.minchar + 4)) { F = (F + 12) } else { if (C.length >= (B.minchar + 5)) { F = (F + 18) } } } } if (C.match(/[a-z]/)) { F = (F + 1) } if (C.match(/[A-Z]/)) { F = (F + 5) } if (C.match(/\d+/)) { F = (F + 5) } if (C.match(/(.*[0-9].*[0-9].*[0-9])/)) { F = (F + 7) } if (C.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) { F = (F + 5) } if (C.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) { F = (F + 7) } if (C.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) { F = (F + 2) } if (C.match(/([a-zA-Z])/) && C.match(/([0-9])/)) { F = (F + 3) } if (C.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) { F = (F + 3) } for (var D = 0; D < B.common.length; D++) { if (C.toLowerCase() == B.common[D]) { F = -200 } } return F } 
    })
})(jQuery)
Posted
Updated 7-Mar-12 1:33am
v2
Comments
OriginalGriff 7-Mar-12 6:35am    
Perhaps, if you want us to look at code, making it a bit readable would help. Format it! Indent it! Help us to help you!
Use the "Improve question" widget to edit your question and provide better information.
Pete O'Hanlon 7-Mar-12 6:54am    
That's the minified version of the JavaScript file. There's not much he can do - this is what's sent to the browser.
OriginalGriff 7-Mar-12 7:19am    
AH! That makes some sense.
I'm still not going to try and read it though...:laugh:
P.Salini 7-Mar-12 6:37am    
format your code in a readable way so that we can understand your problem.

You're not supposed to understand it - the "-min" in the filename means that the original code has been minified to make it smaller.

If you can find a version of the plugin without the "-min" in its filename, you might have better luck with reading it.
 
Share this answer
 
hey - first off, use this to beautify what were' looking at:

http://jsbeautifier.org/[^]


if you wanna understand what its doing - your gonna have to do a bit of reading about 'Regex', as thats what its using to test the integrity of the password.

http://www.regular-expressions.info/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900