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