window.ds=window.ds||{}; ds.password={defaults:{displayMinChar:false,minChar:8,minCharText:"You must enter a minimum of %d characters",colors:["#f00","#c06","#f60","#3c0","#3f0"],scores:[20,30,43,50],verdicts:[_lg("Faible"),_lg("Normal"),_lg("Moyen"),_lg("Fort"),_lg("Tr\u00e8s fort")],raisePower:1.4,contenant:null,debug:false},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(b){ds.password.tooShort=false;b=b.length;var a=Math.pow(b,ds.password.options.raisePower);if(b<ds.password.options.minChar){a-=100;ds.password.tooShort=true}return a},lowercase:function(b,a){return b.match(/[a-z]/)&&a},uppercase:function(b,a){return b.match(/[A-Z]/)&&a},one_number:function(b, a){return b.match(/\d+/)&&a},three_numbers:function(b,a){return b.match(/(.*[0-9].*[0-9].*[0-9])/)&&a},one_special_char:function(b,a){return b.match(/.[!,@,#,$,%,\^,&,*,?,_,~]/)&&a},two_special_char:function(b,a){return b.match(/(.*[!,@,#,$,%,\^,&,*,?,_,~].*[!,@,#,$,%,\^,&,*,?,_,~])/)&&a},upper_lower_combo:function(b,a){return b.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)&&a},letter_number_combo:function(b,a){return b.match(/([a-zA-Z])/)&&b.match(/([0-9])/)&&a},letter_number_char_combo:function(b,a){return b.match(/([a-zA-Z0-9].*[!,@,#,$,%,\^,&,*,?,_,~])|([!,@,#,$,%,\^,&,*,?,_,~].*[a-zA-Z0-9])/)&& a}},attachWidget:function(b){var a=ds.password,c=['<div class="password-strength">'];a.options.displayMinChar&&!a.tooShort&&c.push('<span class="password-min-char">'+a.options.minCharText.replace("%d",a.options.minChar)+"</span>");c.push('<span class="password-strength-bar"></span>');c.push("</div>");c=c.join("");a.options.contenant?a.options.contenant.html(c):jQuery(b).after(c)},debugOutput:function(){typeof console.log==="function"?console.log(ds.password):alert(ds.password)},addRule:function(b, a,c,d){var e=ds.password;e.rules[b]=d;e.ruleScores[b]=c;e.validationRules[b]=a;return true},init:function(b,a){var c=ds.password;c.options=jQuery.extend({},c.defaults,a);c.attachWidget(b);jQuery(b).keyup(function(){c.calculateScore(jQuery(this).val())});c.options.debug&&c.debugOutput()},calculateScore:function(b){var a=ds.password;a.totalscore=0;a.width=0;for(var c in a.rules)if(a.rules.hasOwnProperty(c)){if(a.rules[c]===true){var d=a.ruleScores[c];if(d=a.validationRules[c](b,d))a.totalscore+=d}if(a.totalscore<= a.options.scores[0]){a.strColor=a.options.colors[0];a.strText=a.options.verdicts[0];a.width="1"}else if(a.totalscore>a.options.scores[0]&&a.totalscore<=a.options.scores[1]){a.strColor=a.options.colors[1];a.strText=a.options.verdicts[1];a.width="25"}else if(a.totalscore>a.options.scores[1]&&a.totalscore<=a.options.scores[2]){a.strColor=a.options.colors[2];a.strText=a.options.verdicts[2];a.width="50"}else if(a.totalscore>a.options.scores[2]&&a.totalscore<=a.options.scores[3]){a.strColor=a.options.colors[3]; a.strText=a.options.verdicts[3];a.width="75"}else{a.strColor=a.options.colors[4];a.strText=a.options.verdicts[4];a.width="99"}jQuery(".password-strength-bar").stop();a.options.displayMinChar&&!a.tooShort?jQuery(".password-min-char").hide():jQuery(".password-min-char").show();jQuery(".password-strength-bar").css({display:"block","border-color":a.strColor,width:a.width+"%"}).text(a.strText)}}};jQuery.extend(jQuery.fn,{pstrength:function(b){return this.each(function(){ds.password.init(this,b)})}}); jQuery.extend(jQuery.fn.pstrength,{addRule:function(b,a,c,d){ds.password.addRule(b,a,c,d);return true},changeScore:function(b,a){ds.password.ruleScores[b]=a;return true},ruleActive:function(b,a){ds.password.rules[b]=a;return true}});
