ÿØÿà JFIF ` ` ÿþ
|
Server : Apache System : Linux cloud.heroica.com.br 4.18.0-553.36.1.el8_10.x86_64 #1 SMP Wed Jan 22 03:07:54 EST 2025 x86_64 User : farolpborg ( 1053) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/farolpborg/public_html/cms/_assets/js/ |
Upload File : |
/*!
* strength.js
* Original author: @aaronlumsden
* Further changes, comments: @aaronlumsden
* Licensed under the MIT license
*/
;(function ( $, window, document, undefined ){
var pluginName = "strength",
defaults = {
strengthClass: 'strength',
strengthMeterClass: 'stm',
strengthButtonClass: 'button_strength',
strengthButtonText: 'Show Password',
strengthButtonTextToggle: 'Hide Password'
};
// $('<style>body { background-color: red; color: white; }</style>').appendTo('head');
function Plugin( element, options ){
this.element = element;
this.$elem = $(this.element);
this.options = $.extend( {}, defaults, options );
this._defaults = defaults;
this._name = pluginName;
this.init();
}
Plugin.prototype = {
init: function(){
var characters = 0;
var capitalletters = 0;
var loweletters = 0;
var number = 0;
var special = 0;
var upperCase= new RegExp('[A-Z]');
var lowerCase= new RegExp('[a-z]');
var numbers = new RegExp('[0-9]');
var specialchars = new RegExp('([!,%,&,@,#,$,^,*,?,_,~])');
function GetPercentage(a, b){
return ((b / a) * 100);
}
function check_strength(thisval,thisid){
if (thisval.length > 8){ characters = 1; } else { characters = 0; };
if (thisval.match(upperCase)){ capitalletters = 1} else { capitalletters = 0; };
if (thisval.match(lowerCase)){ loweletters = 1} else { loweletters = 0; };
if (thisval.match(numbers)){ number = 1} else { number = 0; };
var total = characters + capitalletters + loweletters + number + special;
var totalpercent = GetPercentage(7, total).toFixed(0);
get_total(total,thisid);
}
function get_total(total,thisid){
var thismeter = $('div[data-meter="'+thisid+'"]');
if(total == 0){
thismeter.removeClass().css('display','none').html('');
thismeter.css('display','none');
} else if (total <= 1){
thismeter.removeClass();
thismeter.addClass('mfrac').html('Muito fraco');
thismeter.css('display','block');
} else if (total == 2){
thismeter.removeClass();
thismeter.addClass('fraco').html('Fraco');
thismeter.css('display','block');
} else if(total == 3){
thismeter.removeClass();
thismeter.addClass('medio').html('Médio');
thismeter.css('display','block');
} else {
thismeter.removeClass();
thismeter.addClass('forte').html('Forte');
}
console.log(total);
}
var isShown = false;
var strengthButtonText = this.options.strengthButtonText;
var strengthButtonTextToggle = this.options.strengthButtonTextToggle;
thisid = this.$elem.attr('id');
this.$elem.addClass(this.options.strengthClass).attr('data-password',thisid).after('<small class="'+this.options.strengthMeterClass+'"><div style="display:none;" data-meter="'+thisid+'"></div></small>');
this.$elem.bind('keyup keydown focus', function(event){
thisval = $('#'+thisid).val();
$('input[type="text"][data-password="'+thisid+'"]').val(thisval);
check_strength(thisval,thisid);
});
$('input[type="text"][data-password="'+thisid+'"]').bind('keyup keydown focus', function(event){
thisval = $('input[type="text"][data-password="'+thisid+'"]').val();
console.log(thisval);
$('input[type="password"][data-password="'+thisid+'"]').val(thisval);
check_strength(thisval,thisid);
});
$(document.body).on('click', '.'+this.options.strengthButtonClass, function(e){
e.preventDefault();
thisclass = 'hide_'+$(this).attr('class');
if (isShown){
$('input[type="text"][data-password="'+thisid+'"]').hide();
$('input[type="password"][data-password="'+thisid+'"]').show().focus();
$('a[data-password-button="'+thisid+'"]').removeClass(thisclass)(strengthButtonText);
isShown = false;
} else {
$('input[type="text"][data-password="'+thisid+'"]').show().focus();
$('input[type="password"][data-password="'+thisid+'"]').hide();
$('a[data-password-button="'+thisid+'"]').addClass(thisclass)(strengthButtonTextToggle);
isShown = true;
}
});
},
yourOtherFunction: function(el, options){
// some logic
}
};
// A really lightweight plugin wrapper around the constructor,
// preventing against multiple instantiations
$.fn[pluginName] = function ( options ){
return this.each(function (){
if (!$.data(this, "plugin_" + pluginName)){
$.data(this, "plugin_" + pluginName, new Plugin( this, options ));
}
});
};
})( jQuery, window, document );