1/* 2 * passtrength - v1.0.0 3 * passtrength 4 * passtrength 5 * 6 * Made by @adrisorribas 7 * Under MIT License 8 */ 9;(function($, window, document, undefined) { 10 11 var pluginName = "passtrength", 12 defaults = { 13 minChars: 8, 14 passwordToggle: true, 15 tooltip: true, 16 textWeak: "Pessima", 17 textMedium: "Media", 18 textStrong: "Robusta", 19 textVeryStrong: "Molto robusta", 20 eyeImg : "assets/css/passtrength/eye.svg", 21 callback: "" 22 }; 23 24 function Plugin(element, options){ 25 this.element = element; 26 this.$elem = $(this.element); 27 this.options = $.extend({}, defaults, options); 28 this._defaults = defaults; 29 this._name = pluginName; 30 _this = this; 31 this.init(); 32 } 33 34 Plugin.prototype = { 35 init: function(){ 36 var _this = this, 37 meter = jQuery("<div/>", {class: "passtrengthMeter"}), 38 tooltip = jQuery("<div/>", {class: "tooltip", text: "Min " + this.options.minChars + " chars"}); 39 40 meter.insertAfter(this.element); 41 $(this.element).appendTo(meter); 42 43 if(this.options.tooltip){ 44 tooltip.appendTo(meter); 45 var tooltipWidth = tooltip.outerWidth() / 2; 46 tooltip.css("margin-left", -tooltipWidth); 47 } 48 49 this.$elem.bind("keyup keydown", function() { 50 value = $(this).val(); 51 _this.check(value); 52 }); 53 54 if(this.options.passwordToggle){ 55 _this.togglePassword(); 56 } 57 58 }, 59 60 check: function(value){ 61 var secureTotal = 0, 62 chars = 0, 63 capitals = 0, 64 numbers = 0, 65 special = 0; 66 upperCase = new RegExp("[A-Z]"), 67 numbers = new RegExp("[0-9]"), 68 specialchars = new RegExp("([!,%,&,@,#,$,^,*,?,_,~])"); 69 70 if(value.length >= this.options.minChars){ 71 chars = 1; 72 }else{ 73 chars = -1; 74 } 75 if(value.match(upperCase)){ 76 capitals = 1; 77 }else{ 78 capitals = 0; 79 } 80 if(value.match(numbers)){ 81 numbers = 1; 82 }else{ 83 numbers = 0; 84 } 85 if(value.match(specialchars)){ 86 special = 1; 87 }else{ 88 special = 0; 89 } 90 91 secureTotal = chars + capitals + numbers + special; 92 securePercentage = (secureTotal / 4) * 100; 93 94 if(typeof (this.options.callback)=="function"){ 95 this.options.callback(securePercentage); 96 } 97 98 this.addStatus(securePercentage); 99 100 }, 101 102 addStatus: function(percentage){ 103 var status = "", 104 text = "Min " + this.options.minChars + " chars", 105 meter = $(this.element).closest(".passtrengthMeter"), 106 tooltip = meter.find(".tooltip"); 107 108 meter.attr("class", "passtrengthMeter"); 109 110 if(percentage >= 25){ 111 meter.attr("class", "passtrengthMeter"); 112 status = "weak"; 113 text = this.options.textWeak; 114 } 115 if(percentage >= 50){ 116 meter.attr("class", "passtrengthMeter"); 117 status = "medium"; 118 text = this.options.textMedium; 119 $(this.element).trigger("passok"); 120 } 121 if(percentage >= 75){ 122 meter.attr("class", "passtrengthMeter"); 123 status = "strong"; 124 text = this.options.textStrong; 125 } 126 if(percentage >= 100){ 127 meter.attr("class", "passtrengthMeter"); 128 status = "very-strong"; 129 text = this.options.textVeryStrong; 130 } 131 meter.addClass(status); 132 if(this.options.tooltip){ 133 tooltip.text(text); 134 } 135 }, 136 137 togglePassword: function(){ 138 var buttonShow = jQuery("<span/>", {class: "showPassword", html: "<img src="+ this.options.eyeImg +" />"}), 139 input = jQuery("<input/>", {type: "text"}), 140 passwordInput = this; 141 142 buttonShow.appendTo($(this.element).closest(".passtrengthMeter")); 143 input.appendTo($(this.element).closest(".passtrengthMeter")).hide(); 144 145 $(this.element).bind("keyup keydown", function() { 146 input.val($(passwordInput.element).val()); 147 }); 148 149 input.bind("keyup keydown", function() { 150 $(passwordInput.element).val(input.val()); 151 value = $(this).val(); 152 _this.check(value); 153 }); 154 155 $(document).on("click", ".showPassword", function() { 156 buttonShow.toggleClass("active");
157 input.toggle(); 158 $(passwordInput.element).toggle(); 159 }); 160 } 161 }; 162 163 $.fn[pluginName] = function(options) { 164 return this.each(function() { 165 if (!$.data(this, "plugin_" + pluginName)) { 166 $.data(this, "plugin_" + pluginName, new Plugin(this, options)); 167 } 168 }); 169 }; 170 171})(jQuery, window, document);
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.