jQuery Password Meter
Submitted by PiTiLeZarD on Tue, 07/31/2007 - 16:52
Tagged:
J'ai regardé il existe un plugin qui fait ça ... mais bon ... pas top !
J'ai donc développé le mien a partir d'un truc que j'ai trouvé ailleur et que j'ai adapté a la sauce jQuery.
- Voici la démo
- Comment on s'en sert ? $('#password').passwordMeter($('#progressbar'));
- L'adaptation :
(function($) { $.passwordMeter = { tolerance: 35, // normally to have hard password, you should have 45 here status:null, lastStatus: 0, init: function(div) { $.passwordMeter.lastStatus = 0; var statusID = div.attr('id')+'_status'; div.html('<div id="'+statusID+'"></div>'); var status = $('#'+statusID); $.passwordMeter.status = status; status.html(''); status.css('width', '0'); status.css('height', div.css('height')); }, passwordCheck: function() { var score = $.passwordMeter.testPassword(this.value); score = parseInt('' + (score / $.passwordMeter.tolerance * 100)); if (score > 100) score = 100; if (score != $.passwordMeter.lastStatus) { $.passwordMeter.status.css('width', score+'%'); $.passwordMeter.lastStatus = score; } }, testPassword: function(passwd){ // Based on this post : http://www.geekwisdom.com/dyn/passwdmeter var intScore = 0 if (passwd == undefined) return 0; // PASSWORD LENGTH if (passwd.length<5) intScore = (intScore+3); else if (passwd.length>4 && passwd.length<8) intScore = (intScore+6); else if (passwd.length>7 && passwd.length<16) intScore = (intScore+12); else if (passwd.length>15) intScore = (intScore+18); // LETTERS if (passwd.match(/[a-z]/)) intScore = (intScore+1); if (passwd.match(/[A-Z]/)) intScore = (intScore+5); // NUMBERS if (passwd.match(/\d+/)) intScore = (intScore+5); if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) intScore = (intScore+5); // SPECIAL CHAR if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/)) intScore = (intScore+5); if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)) intScore = (intScore+5); // COMBOS if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) intScore = (intScore+2); if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) intScore = (intScore+2); if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/)) intScore = (intScore+2); return intScore; } }; $.fn.passwordMeter = function(div) { $.passwordMeter.init(div); this.keyup($.passwordMeter.passwordCheck); }; })(jQuery);

Comments
Bonjour,
Cet article est très intéressant. Parler de JQuery est une action
d'utilité publique pour le web.
Vous pouvez consulter plus d'informations sur le site http://www.webjax.eu
et plus particulièrement la rubrique http://www.webjax.eu/r/14-JQuery-javascript-framework-ajax-library-jquery-j-query-Framework-Javascript-Library-Ajax-asyncronous-web2.0-ria-dom-control-enhancer
qui présente la documentation officielle de Jquery en version française.
Vive le web2.0 et ajax, longue vie aux codeurs :-)