1/** 2 * password_strength_plugin.js 3 * Copyright (c) 2009 myPocket technologies (www.mypocket-technologies.com) 4 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 15 * View the GNU General Public License <http://www.gnu.org/licenses/>. 16 17 * @author Darren Mason ([email protected]) 18 * @date 1/23/2009 19 * @projectDescription Password Strength Meter is a jQuery plug-in provide you smart algorithm to detect a password strength. Based on Firas Kassem orginal plugin - http://phiras.wordpress.com/2007/04/08/password-strength-meter-a-jquery-plugin/ 20 * @version 1.0.0 21 * 22 * @requires jquery.js (tested with 1.3.1) 23 * @param shortPass: "shortPass", //optional 24 * @param badPass: "badPass", //optional 25 * @param goodPass: "goodPass", //optional 26 * @param strongPass: "strongPass", //optional 27 * @param baseStyle: "testresult", //optional 28 * @param userid: "", //required override 29 * @param messageloc: 1 //before == 0 or after == 1 30 * 31*/ 32 33(function($){ 34 $.fn.shortPass = 'СлиÑком коÑоÑкий паÑолÑ'; 35 $.fn.badPass = 'СлабÑй паÑолÑ'; 36 $.fn.goodPass = 'ÐоÑмалÑнÑй паÑолÑ'; 37 $.fn.strongPass = 'СилÑнÑй паÑолÑ'; 38 $.fn.samePassword = 'ÐÐ¼Ñ Ð¿Ð¾Ð»ÑзоваÑÐµÐ»Ñ Ð¸ паÑÐ¾Ð»Ñ Ð¸Ð´ÐµÐ½ÑиÑнÑ.'; 39 $.fn.resultStyle = ""; 40 41 $.fn.passStrength = function(options) { 42 43 var defaults = { 44 shortPass: "shortPass", //optional 45 badPass: "badPass", //optional 46 goodPass: "goodPass", //optional 47 strongPass: "strongPass", //optional 48 baseStyle: "testresult", //optional 49 userid: "", //required override 50 messageloc: 1 //before == 0 or after == 1 51 }; 52 var opts = $.extend(defaults, options); 53 54 return this.each(function() { 55 var obj = $(this); 56 57 $(obj).keyup(function() 58 { 59 60 var results = $.fn.teststrength($(this).val(),$(opts.userid).val(),opts); 61 62 if(opts.messageloc === 1) 63 { 64 $(this).next("." + opts.baseStyle).remove(); 65 $(this).after("<b class=\""+opts.baseStyle+"\"><span></span></b>"); 66 $(this).next("." + opts.baseStyle).addClass($(this).resultStyle).find("span").text(results); 67 } 68 else 69 { 70 $(this).prev("." + opts.baseStyle).remove(); 71 $(this).before("<b class=\""+opts.baseStyle+"\"><span></span></b>"); 72 $(this).prev("." + opts.baseStyle).addClass($(this).resultStyle).find("span").text(results); 73 } 74 }); 75 76 //FUNCTIONS 77 $.fn.teststrength = function(password,username,option){ 78 var score = 0; 79 80 //password < 4 81 if (password.length < 4 ) { this.resultStyle = option.shortPass;return $(this).shortPass; } 82 83 //password == user name 84 if (password.toLowerCase()==username.toLowerCase()){this.resultStyle = option.badPass;return $(this).samePassword;} 85 86 //password length 87 score += password.length * 4; 88 score += ( $.fn.checkRepetition(1,password).length - password.length ) * 1; 89 score += ( $.fn.checkRepetition(2,password).length - password.length ) * 1; 90 score += ( $.fn.checkRepetition(3,password).length - password.length ) * 1; 91 score += ( $.fn.checkRepetition(4,password).length - password.length ) * 1; 92 93 //password has 3 numbers 94 if (password.match(/(.*[0-9].*[0-9].*[0-9])/)){ score += 5;} 95 96 //password has 2 symbols 97 if (password.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/)){ score += 5 ;} 98 99 //password has Upper and Lower
99chars 100 if (password.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)){ score += 10;} 101 102 //password has number and chars 103 if (password.match(/([a-zA-Z])/) && password.match(/([0-9])/)){ score += 15;} 104 // 105 //password has number and symbol 106 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([0-9])/)){ score += 15;} 107 108 //password has char and symbol 109 if (password.match(/([!,@,#,$,%,^,&,*,?,_,~])/) && password.match(/([a-zA-Z])/)){score += 15;} 110 111 //password is just a numbers or chars 112 if (password.match(/^\w+$/) || password.match(/^\d+$/) ){ score -= 10;} 113 114 //verifying 0 < score < 100 115 if ( score < 0 ){score = 0;} 116 if ( score > 100 ){ score = 100;} 117 118 if (score < 34 ){ this.resultStyle = option.badPass; return $(this).badPass;} 119 if (score < 68 ){ this.resultStyle = option.goodPass;return $(this).goodPass;} 120 121 this.resultStyle= option.strongPass; 122 return $(this).strongPass; 123 124 }; 125 126 }); 127 }; 128})(jQuery); 129 130 131$.fn.checkRepetition = function(pLen,str) { 132 var res = ""; 133 for (var i=0; i<str.length ; i++ ) 134 { 135 var repeated=true; 136 137 for (var j=0;j < pLen && (j+i+pLen) < str.length;j++){ 138 repeated=repeated && (str.charAt(j+i)==str.charAt(j+i+pLen)); 139 } 140 if (j<pLen){repeated=false;} 141 if (repeated) { 142 i+=pLen-1; 143 repeated=false; 144 } 145 else { 146 res+=str.charAt(i); 147 } 148 } 149 return res; 150 };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.