/**
 * @author Ã’scar Casajuana a.k.a. elboletaire <elboletaire at underave dot net>
 * @link https://github.com/elboletaire/password-strength-meter
 * @license GPL-3.0
 */
!function(u){"use strict";function t(l,c){function i(e,t){for(var s="",r=!1,a=0;a<t.length;a++){r=!0;for(var o=0;o<e&&o+a+e<t.length;o++)r=r&&t.charAt(o+a)===t.charAt(o+a+e);o<e&&(r=!1),r?(a+=e-1,r=!1):s+=t.charAt(a)}return s}function h(e,t){var s;return c.useColorBarImage?e.css({backgroundPosition:"0px -"+t+"px",width:t+"%"}):(s=function(e){var t=0,s=240,r=0,a=240,o=10;Object.prototype.hasOwnProperty.call(c.customColorBarRGB,"red")&&(t=c.customColorBarRGB.red[0],s=c.customColorBarRGB.red[1]),Object.prototype.hasOwnProperty.call(c.customColorBarRGB,"green")&&(r=c.customColorBarRGB.green[0],a=c.customColorBarRGB.green[1]),Object.prototype.hasOwnProperty.call(c.customColorBarRGB,"blue")&&(o=c.customColorBarRGB.blue);var n=e*a/50,l=2*s-e*s/50;return{red:Math.min(Math.max(l,t),s),green:Math.min(Math.max(n,r),a),blue:o}}(t),e.css({"background-image":"none","background-color":"rgb("+s.red.toString()+", "+s.green.toString()+", "+s.blue.toString()+")",width:t+"%"})),e}return c=u.extend({},{enterPass:"Type your password",shortPass:"The password is too short",containsField:"The password contains your username",steps:{13:"Really insecure password",33:"Weak; try combining letters & numbers",67:"Medium; try using special characters",94:"Strong password"},showPercent:!1,showText:!0,animate:!0,animateSpeed:"fast",field:!1,fieldPartialMatch:!0,minimumLength:4,closestSelector:"div",useColorBarImage:!1,customColorBarRGB:{red:[0,240],green:[0,240],blue:10}},c),function(){var e=!0,a=c.showText,o=c.showPercent,t=u("<div>").addClass("pass-graybar"),n=u("<div>").addClass("pass-colorbar"),s=u("<div>").addClass("pass-wrapper").append(t.append(n));return l.closest(c.closestSelector).addClass("pass-strength-visible"),c.animate&&(s.css("display","none"),e=!1,l.closest(c.closestSelector).removeClass("pass-strength-visible")),c.showPercent&&(o=u("<span>").addClass("pass-percent").text("0%"),s.append(o)),c.showText&&(a=u("<span>").addClass("pass-text").html(c.enterPass),s.append(a)),l.closest(c.closestSelector).append(s),l.keyup(function(){var e=(e=c.field||"")&&u(e).val(),t=function(e,t){var s=0;if(e.length<c.minimumLength)return-1;if(c.field){if(e.toLowerCase()===t.toLowerCase())return-2;if(c.fieldPartialMatch&&t.length){var r=new RegExp(t.toLowerCase());if(e.toLowerCase().match(r))return-2}}s+=4*e.length,s+=i(1,e).length-e.length,s+=i(2,e).length-e.length,s+=i(3,e).length-e.length,s+=i(4,e).length-e.length,e.match(/(.*[0-9].*[0-9].*[0-9])/)&&(s+=5);var a=".*[!,@,#,$,%,^,&,*,?,_,~]",a=new RegExp("("+a+a+")");return e.match(a)&&(s+=5),e.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)&&(s+=10),e.match(/([a-zA-Z])/)&&e.match(/([0-9])/)&&(s+=15),e.match(/([!@#$%^&*?_~])/)&&e.match(/([0-9])/)&&(s+=15),e.match(/([!@#$%^&*?_~])/)&&e.match(/([a-zA-Z])/)&&(s+=15),(e.match(/^\w+$/)||e.match(/^\d+$/))&&(s-=10),100<s&&(s=100),s<0&&(s=0),s}(l.val(),e);l.trigger("password.score",[t]);var s,r=t<0?0:t;n=h(n,r),c.showPercent&&o.html(r+"%"),c.showText&&(s=function(e){if(-1===e)return c.shortPass;if(-2===e)return c.containsField;e=e<0?0:e;var t=c.shortPass,s=Object.keys(c.steps).sort();for(var r in s){var a=s[r];a<e&&(t=c.steps[a])}return t}(t),!l.val().length&&t<=0&&(s=c.enterPass),a.html()!==u("<div>").html(s).html()&&(a.html(s),l.trigger("password.text",[s,t])))}),c.animate&&(l.focus(function(){e||s.slideDown(c.animateSpeed,function(){e=!0,l.closest(c.closestSelector).addClass("pass-strength-visible")})}),l.blur(function(){!l.val().length&&e&&s.slideUp(c.animateSpeed,function(){e=!1,l.closest(c.closestSelector).removeClass("pass-strength-visible")})})),this}.call(this)}u.fn.password=function(e){return this.each(function(){new t(u(this),e)})}}(jQuery);