A JQuery plugin that converts a password input into an advanced widget with strength validation meter and toggle mask to show/hide the password. The password strength is validated as you type. View a complete demo.
Not seeing the updated content on this page! Hard refresh your browser to clean cache for this page (e.g. SHIFT-F5 on Windows Chrome)
rules
.type = password
to the strength validation plugin if you set its class = strength
. All options to the password input can be passed as HTML5 data
attributes.The strength-meter plugin can be installed automatically or manually using one of these options:
Installation via bower package manager is as simple as running:
$ bower install strength-meter
Step 1: Load the following assets in your header.
<!-- bootstrap 4.x is supported. You can also use the bootstrap css 3.3.x versions --> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css"> <link href="path/to/css/strength-meter.min.css" media="all" rel="stylesheet" type="text/css" /> <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script> <script src="path/to/js/strength-meter.min.js" type="text/javascript"></script>
If you noticed, you need to load the jquery.min.js
and bootstrap.min.css
in addition to the strength-meter.min.css
and strength-meter.min.js
.
bootstrap.min.css
if you do not need Bootstrap 3.x styling. To use your own style, you need to setup the inputTemplate, meterTemplate, and mainTemplate options to match your CSS Styling needs.
Step 2: Locale/language specific assets.
In addition, you can load a locale specific script for your language specific translation. For example to load German translations:
<script src="path/to/js/locales/strength-meter-de.js" type="text/javascript"></script>
Step 3a: Initialize the plugin on your page. For example,
// initialize with defaults $("#password-id").strength(); // with plugin options $("#password-id").strength({showMeter: true, toggleMask: false});
The #password-id
is the identifier for the password input (type=password
) on your page.
Step 3b: Alternatively, you can directly set the plugin options to any input, through HTML 5 data attributes to your input field.
<input id="password-id" type="password" class="strength" data-toggle-title="Display Password">
[input type="password"]
to a star strength control, if you attach a css class strength
to the input.
The plugin supports these following options:
string language configuration for the plugin to enable the plugin to display messages for your locale (you
must set the ISO code for the language). You can have multiple language widgets on the same page. Note you must load the language specific locale file strength-meter-<LANG>.js
available in the js/locales
folder of the plugin. The file must be loaded after strength-meter.js
.
boolean whether to display the checkbox for toggling display of password text. Defaults to true
.
string the template for displaying the password input field (when toggleMask
is true
). This defaults to:
<div class="input-group"> {input} <span class="input-group-addon">{toggle}</span> </div>
The following special tokens will be replaced in the template:
{input}
will be replaced with the password input.
{toggle}
will be replaced with the toggle mask checkbox.
string the template for displaying the password input field(when toggleMask
is false
). This defaults to:
{input}
The following special tokens will be replaced in the template:
{input}
will be replaced with the password input.
string the template for displaying the password strength meter. This defaults to:
<div class="kv-scorebar-border"> {scorebar} {score} </div> {verdict}
The following special tokens will be replaced in the template:
{scorebar}
will be replaced with the strength score color bar.
{score}
will be replaced with the strength score in %.
{verdict}
will be replaced with the calculated strength verdict.
string the template for displaying the overall widget/plugin. This defaults to:
<table class="kv-container"> <tr> <td>{input}</td> <td class="kv-meter-container">{meter}</td> </tr> </table>
The following special tokens will be replaced in the template:
{input}
will be replaced with the parsed output from the inputTemplate.
{meter}
will be replaced with the parsed output from the meterTemplate.
string the CSS class for displaying the strength score color bar. Defaults to kv-scorebar
.
string the title to be displayed on hovering the toggle mask checkbox. Defaults to Show/Hide Password
. If you load in a locale specific JS, this will be overridden with the language specific toggleTitle
.
array the verdict titles corresponding to each strength verdict (0 to 6). If you load in a locale specific JS, this will be overridden with the language specific verdict. Defaults to:
{ 0: 'Too Short', 1: 'Very Weak', 2: 'Weak', 3: 'Good', 4: 'Strong', 5: 'Very Strong', }
array the verdict CSS classes corresponding to each strength verdict (0 to 6). Defaults to:
{ 0: 'badge bg-default', 1: 'badge bg-danger', 2: 'badge bg-warning', 3: 'badge bg-info', 4: 'badge bg-primary', 5: 'badge bg-success', }
array the strength validation rules. You normally do not need to change this, as this will impact the strength score algorithm. Defaults to:
{ midChar: 2, consecAlphaUC: 2, consecAlphaLC: 2, consecNumber: 2, seqAlpha: 3, seqNumber: 3, seqSymbol: 3, length: 4, number: 4, symbol: 6 }
Each rule element corresponds to the following:
midChar
: The multiplication factor (addition) for middle numbers or symbols.
consecAlphaUC
: The multiplication factor (reduction) for consecutive upper case alphabets.
consecAlphaLC
: The multiplication factor (reduction) for consecutive lower case alphabets.
consecNumber
: The multiplication factor (reduction) for consecutive numbers.
seqAlpha
: The multiplication factor (reduction) for sequential alphabets (3+).
seqNumber
: The multiplication factor (reduction) for sequential numbers (3+).
seqSymbol
: The multiplication factor (reduction) for sequential symbols (3+).
length
: The multiplication factor (addition) for the count of characters.
number
: The multiplication factor (addition) for count of numbers in the input.
symbol
: The multiplication factor (addition) for count of symbols in the input.
The plugin supports these events:
This event is triggered when the password input/strength is changed.
Example:
$('#input-id').on('strength:change', function(event) { console.log("strength:change"); });
The plugin supports these methods:
Refreshes the strength after changing the password input value via javascript.
$('#input-id').val(3); $('#input-id').strength('refresh');
The plugin has been implemented as extensions in the following frameworks
Sl. | Framework | Extension Source | Developed By | Extension Demo |
---|---|---|---|---|
1. | Yii Framework 2.0 | Yii2 Password | Krajee | Yii2 Password Input |
Do you know any other framework extension using this plugin which is not listed here? Tell us so that we can consider its inclusion in this list.
strength-meter is released under the BSD 3-Clause License. See the bundled LICENSE.md
for details.
Comments & Discussion
Note
You can now visit the Krajee Webtips Q & A forum for searching OR asking questions OR helping programmers with answers on these extensions and plugins. For asking a question click here. Select the appropriate question category (i.e. Krajee Plugins) and choose this current page plugin in the question related to field.
The comments and discussion section below are intended for generic discussions or feedback for this plugin. Developers may not be able to search or lookup here specific questions or tips on usage for this plugin.