/* @projectDescription jQuery Password Strength Plugin - A jQuery plugin to provide accessibility functions
 * @author Tane Piper (digitalspaghetti@gmail.com)
 * @version 2.0
 * @website: http://digitalspaghetti.me.uk/digitalspaghetti
 * @license MIT License: http://www.opensource.org/licenses/mit-license.php
 */
window.digitalspaghetti=window.digitalspaghetti||{};digitalspaghetti.password={defaults:{displayMinChar:true,minChar:8,minCharText:"You must enter a minimum of %d characters",colors:["#f00","#c06","#f60","#3c0","#3f0"],scores:[20,30,43,50],verdicts:["Weak","Normal","Medium","Strong","Very Strong"],raisePower:1.4},ruleScores:{length:0,lowercase:1,uppercase:3,one_number:3,three_numbers:5,one_special_char:3,two_special_char:5,upper_lower_combo:2,letter_number_combo:2,letter_number_char_combo:2},rules:{length:true,lowercase:true,uppercase:true,one_number:true,three_numbers:true,one_special_char:true,two_special_char:true,upper_lower_combo:true,letter_number_combo:true,letter_number_char_combo:true},validationRules:{length:function(C,D){var A=C.length;var B=Math.pow(A,digitalspaghetti.password.options.raisePower);if(A<digitalspaghetti.password.options.minChar){B=(B-100)}return B},lowercase:function(A,B){return A.match(/[a-z]/)&&B},uppercase:function(A,B){return A.match(/[A-Z]/)&&B},one_number:function(A,B){return A.match(/\d+/)&&B},three_numbers:function(A,B){return A.match(/(.*[0-9].*[0-9].*[0-9])/)&&B},one_special_char:function(A,B){return A.match(/.[!,@,#,$,%,\^,&,*,?,_,~]/)&&B},two_special_char:function(A,B){return A.match(/(.*[!,@,#,$,%,\^,&,*,?,_,~].*[!,@,#,$,%,\^,&,*,?,_,~])/)&&B},upper_lower_combo:function(A,B){return A.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)&&B},letter_number_combo:function(A,B){return A.match(/([a-zA-Z])/)&&A.match(/([0-9])/)&&B},letter_number_char_combo:function(A,B){return A.match(/([a-zA-Z0-9].*[!,@,#,$,%,\^,&,*,?,_,~])|([!,@,#,$,%,\^,&,*,?,_,~].*[a-zA-Z0-9])/)&&B}},attachWidget:function(B){var A=['<div id="password-strength">'];if(digitalspaghetti.password.options.displayMinChar){A.push('<span class="password-min-char">'+digitalspaghetti.password.options.minCharText.replace("%d",digitalspaghetti.password.options.minChar)+"</span>")}A.push('<span class="password-strength-bar"></span>');A.push("</div>");A=A.join("");jQuery(B).after(A)},addRule:function(A,D,C,B){digitalspaghetti.password.rules[A]=B;digitalspaghetti.password.ruleScores[A]=C;digitalspaghetti.password.validationRules[A]=D},init:function(B,A){digitalspaghetti.password.options=jQuery.extend({},digitalspaghetti.password.defaults,A);digitalspaghetti.password.attachWidget(B);jQuery(B).keyup(function(){digitalspaghetti.password.calculateScore(jQuery(this).val())})},calculateScore:function(C){digitalspaghetti.password.totalscore=0;digitalspaghetti.password.width=0;for(var B in digitalspaghetti.password.rules){if(digitalspaghetti.password.rules.hasOwnProperty(B)){if(digitalspaghetti.password.rules[B]===true){var D=digitalspaghetti.password.ruleScores[B];var A=digitalspaghetti.password.validationRules[B](C,D);if(A){digitalspaghetti.password.totalscore+=A}}if(digitalspaghetti.password.totalscore===-200){digitalspaghetti.password.strColor="#f00";digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[0];digitalspaghetti.password.width="0"}else{if(digitalspaghetti.password.totalscore<0&&digitalspaghetti.password.totalscore>-199){digitalspaghetti.password.strColor="#f00";digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[0];digitalspaghetti.password.width="1"}else{if(digitalspaghetti.password.totalscore<=digitalspaghetti.password.options.scores[0]){digitalspaghetti.password.strColor=digitalspaghetti.password.options.colors[0];digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[0];digitalspaghetti.password.width="1"}else{if(digitalspaghetti.password.totalscore>digitalspaghetti.password.options.scores[0]&&digitalspaghetti.password.totalscore<=digitalspaghetti.password.options.scores[1]){digitalspaghetti.password.strColor=digitalspaghetti.password.options.colors[1];digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[1];digitalspaghetti.password.width="25"}else{if(digitalspaghetti.password.totalscore>digitalspaghetti.password.options.scores[1]&&digitalspaghetti.password.totalscore<=digitalspaghetti.password.options.scores[2]){digitalspaghetti.password.strColor=digitalspaghetti.password.options.colors[2];digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[2];digitalspaghetti.password.width="50"}else{if(digitalspaghetti.password.totalscore>digitalspaghetti.password.options.scores[2]&&digitalspaghetti.password.totalscore<=digitalspaghetti.password.options.scores[3]){digitalspaghetti.password.strColor=digitalspaghetti.password.options.colors[3];digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[3];digitalspaghetti.password.width="75"}else{digitalspaghetti.password.strColor=digitalspaghetti.password.options.colors[4];digitalspaghetti.password.strText=digitalspaghetti.password.options.verdicts[4];digitalspaghetti.password.width="99"}}}}}}jQuery(".password-strength-bar").stop();jQuery(".password-strength-bar").animate({opacity:0.5},"fast","linear",function(){jQuery(this).css({display:"block","background-color":digitalspaghetti.password.strColor,width:digitalspaghetti.password.width+"%"}).text(digitalspaghetti.password.strText);jQuery(this).animate({opacity:1},"fast","linear")})}}}};jQuery.extend(jQuery.fn,{pstrength:function(A){return this.each(function(){digitalspaghetti.password.init(this,A)})}});
