Repository: aarondo/Strength.js Branch: master Commit: bfd091789361 Files: 12 Total size: 28.0 KB Directory structure: gitextract_jxu1ub91/ ├── .gitattributes ├── .gitignore ├── README.md ├── demo/ │ ├── simple_example/ │ │ ├── index.html │ │ ├── js.js │ │ ├── strength.css │ │ └── strength.js │ └── styled_example/ │ ├── index.html │ ├── js.js │ └── strength.js └── src/ ├── strength.css └── strength.js ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitattributes ================================================ # Auto detect text files and perform LF normalization * text=auto # Custom for Visual Studio *.cs diff=csharp *.sln merge=union *.csproj merge=union *.vbproj merge=union *.fsproj merge=union *.dbproj merge=union # Standard to msysgit *.doc diff=astextplain *.DOC diff=astextplain *.docx diff=astextplain *.DOCX diff=astextplain *.dot diff=astextplain *.DOT diff=astextplain *.pdf diff=astextplain *.PDF diff=astextplain *.rtf diff=astextplain *.RTF diff=astextplain ================================================ FILE: .gitignore ================================================ ################# ## Eclipse ################# *.pydevproject .project .metadata bin/ tmp/ *.tmp *.bak *.swp *~.nib local.properties .classpath .settings/ .loadpath # External tool builders .externalToolBuilders/ # Locally stored "Eclipse launch configurations" *.launch # CDT-specific .cproject # PDT-specific .buildpath ################# ## Visual Studio ################# ## Ignore Visual Studio temporary files, build results, and ## files generated by popular Visual Studio add-ons. # User-specific files *.suo *.user *.sln.docstates # Build results [Dd]ebug/ [Rr]elease/ x64/ build/ [Bb]in/ [Oo]bj/ # MSTest test Results [Tt]est[Rr]esult*/ [Bb]uild[Ll]og.* *_i.c *_p.c *.ilk *.meta *.obj *.pch *.pdb *.pgc *.pgd *.rsp *.sbr *.tlb *.tli *.tlh *.tmp *.tmp_proj *.log *.vspscc *.vssscc .builds *.pidb *.log *.scc # Visual C++ cache files ipch/ *.aps *.ncb *.opensdf *.sdf *.cachefile # Visual Studio profiler *.psess *.vsp *.vspx # Guidance Automation Toolkit *.gpState # ReSharper is a .NET coding add-in _ReSharper*/ *.[Rr]e[Ss]harper # TeamCity is a build add-in _TeamCity* # DotCover is a Code Coverage Tool *.dotCover # NCrunch *.ncrunch* .*crunch*.local.xml # Installshield output folder [Ee]xpress/ # DocProject is a documentation generator add-in DocProject/buildhelp/ DocProject/Help/*.HxT DocProject/Help/*.HxC DocProject/Help/*.hhc DocProject/Help/*.hhk DocProject/Help/*.hhp DocProject/Help/Html2 DocProject/Help/html # Click-Once directory publish/ # Publish Web Output *.Publish.xml *.pubxml # NuGet Packages Directory ## TODO: If you have NuGet Package Restore enabled, uncomment the next line #packages/ # Windows Azure Build Output csx *.build.csdef # Windows Store app package directory AppPackages/ # Others sql/ *.Cache ClientBin/ [Ss]tyle[Cc]op.* ~$* *~ *.dbmdl *.[Pp]ublish.xml *.pfx *.publishsettings # RIA/Silverlight projects Generated_Code/ # Backup & report files from converting an old project file to a newer # Visual Studio version. Backup files are not needed, because we have git ;-) _UpgradeReport_Files/ Backup*/ UpgradeLog*.XML UpgradeLog*.htm # SQL Server files App_Data/*.mdf App_Data/*.ldf ############# ## Windows detritus ############# # Windows image file caches Thumbs.db ehthumbs.db # Folder config file Desktop.ini # Recycle Bin used on file shares $RECYCLE.BIN/ # Mac crap .DS_Store ############# ## Python ############# *.py[co] # Packages *.egg *.egg-info dist/ build/ eggs/ parts/ var/ sdist/ develop-eggs/ .installed.cfg # Installer logs pip-log.txt # Unit test / coverage reports .coverage .tox #Translations *.mo #Mr Developer .mr.developer.cfg ================================================ FILE: README.md ================================================ Strength.js =========== The ultimate jQuery password input plugin. Featuring secure strength indicator and hide/show password ### Documentation Strength.js provides a toggle feature for password input fields that allows the user to view or asterisk the password. It also features a strength indicator to show how secure a users password is. The password secuirty indicator is marked on 4 scores. These are * Password must contain 8 characters or more * Password must contain 1 lowercase letter * Password must contain 1 uppercase letter * Password must contain 1 number #### ..:: Getting Started ##### Include the relevant files Firstly include jQuery and the strength.css and strength.js files. Place these before `</head>` section ##### Create a password input field You must give your password input a unique ID. ##### Initiate the plugin Once you have created your password input field you will need to initiate the plugin. At its most basic level you can initiate the plugin like: $(document).ready(function ($) { $("#myPassword").strength(); }); If you want to initiate the plugin with options then you can do so like: $('#myPassword').strength({ strengthClass: 'strength', strengthMeterClass: 'strength_meter', strengthButtonClass: 'button_strength', strengthButtonText: 'Show password', strengthButtonTextToggle: 'Hide Password' }); #### ..:: Options
Variable Default Value Description Valid Options
strengthClass strength The CSS class that you want your input field to have
strengthMeterClass strength_meter The CSS class that you want your input field to have
strengthButtonClass button_strength The CSS class that you want the toggle button to have
strengthButtonText Show Password The text that you want to show for the toggle button
strengthButtonTextToggle Hide Password The toggled text that you want to show for the toggle button
================================================ FILE: demo/simple_example/index.html ================================================ Untitled Document
================================================ FILE: demo/simple_example/js.js ================================================ ================================================ FILE: demo/simple_example/strength.css ================================================ @charset "utf-8"; /* CSS Document */ .strength_meter{ height:23px; width: 154px; background:silver; } .strength_meter div{ height:23px; width:100%; height:23px; text-align:center; color:black; font-weight:bold; line-height:23px; } .veryweak{ background-color: #FFA0A0; border-color: #F04040!important } .weak{ background-color: #FFB78C; border-color: #FF853C!important; } .medium{ background-color: #FFEC8B; border-color: #FC0!important; } .strong{ background-color: #C3FF88; border-color: #8DFF1C!important; } ================================================ FILE: demo/simple_example/strength.js ================================================ /*! * 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: 'strength_meter', strengthButtonClass: 'button_strength', strengthButtonText: 'Show Password', strengthButtonTextToggle: 'Hide Password' }; // $('').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().html(''); }else if (total <= 1) { thismeter.removeClass(); thismeter.addClass('veryweak').html('

Strength: very weak

'); } else if (total == 2){ thismeter.removeClass(); thismeter.addClass('weak').html('

Strength: weak

'); } else if(total == 3){ thismeter.removeClass(); thismeter.addClass('medium').html('

Strength: medium

'); } else { thismeter.removeClass(); thismeter.addClass('strong').html('

Strength: strong

'); } 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(''+this.options.strengthButtonText+'

'); this.$elem.bind('keyup keydown', 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', 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).html(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).html(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 ); ================================================ FILE: demo/styled_example/index.html ================================================ Untitled Document



Strength.js

================================================ FILE: demo/styled_example/js.js ================================================ ================================================ FILE: demo/styled_example/strength.js ================================================ /*! * 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: 'strength_meter', strengthButtonClass: 'button_strength', strengthButtonText: 'Show Password', strengthButtonTextToggle: 'Hide Password' }; // $('').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().html(''); }else if (total <= 1) { thismeter.removeClass(); thismeter.addClass('veryweak').html('

Strength: very weak

'); } else if (total == 2){ thismeter.removeClass(); thismeter.addClass('weak').html('

Strength: weak

'); } else if(total == 3){ thismeter.removeClass(); thismeter.addClass('medium').html('

Strength: medium

'); } else { thismeter.removeClass(); thismeter.addClass('strong').html('

Strength: strong

'); } 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(''+this.options.strengthButtonText+'

'); this.$elem.bind('keyup keydown', 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', 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).html(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).html(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 ); ================================================ FILE: src/strength.css ================================================ @charset "utf-8"; /* CSS Document */ .strength_meter{ height:23px; width: 154px; background:silver; } .strength_meter div{ height:23px; width:100%; height:23px; text-align:center; color:black; font-weight:bold; line-height:23px; } .veryweak{ background-color: #FFA0A0; border-color: #F04040!important } .weak{ background-color: #FFB78C; border-color: #FF853C!important; } .medium{ background-color: #FFEC8B; border-color: #FC0!important; } .strong{ background-color: #C3FF88; border-color: #8DFF1C!important; } ================================================ FILE: src/strength.js ================================================ /*! * 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: 'strength_meter', strengthButtonClass: 'button_strength', strengthButtonText: 'Show Password', strengthButtonTextToggle: 'Hide Password' }; // $('').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 = -1; }; 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); if (!thisval.length) {total = -1;} get_total(total,thisid); } function get_total(total,thisid){ var thismeter = $('div[data-meter="'+thisid+'"]'); if (total <= 1) { thismeter.removeClass(); thismeter.addClass('veryweak').html('very weak'); } else if (total == 2){ thismeter.removeClass(); thismeter.addClass('weak').html('weak'); } else if(total == 3){ thismeter.removeClass(); thismeter.addClass('medium').html('medium'); } else { thismeter.removeClass(); thismeter.addClass('strong').html('strong'); } if (total == -1) { thismeter.removeClass().html('Strength'); } } 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(''+this.options.strengthButtonText+'
Strength
'); this.$elem.bind('keyup keydown', 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', 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).html(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).html(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 );