PasswordStrength plugin

Check the strength of a password

Usage

The PasswordStrength plugin uses the popular zxcvbn library to estimate the strength of a password.

The following piece of code is the starting point to use it:

The sample code above assumes that the FormValidation files are placed inside the vendors directory. You might need to change the path depending on where you place them on the server.

Options

* presents a required parameter

Option Type Description
field * String The field name
message String The default error message which will be shown to let user know that the password is weak. It then will be replaced with the warning message of zxcvbn library to indicate the specific reason why the password is weak
minimalScore Number

For a given password, the zxcvbn library will calculate its strength and the score can be one of 0, 1, 2, 3, 4. The password will be treated as invalid if the scroce if less than minimalScore.

The default value is 3

onValidated Function

The callback function that will be triggered after validating the password. The function takes three parameters:

  • valid (Boolean): Can be true or false depending on the field is valid or not
  • message (String): The error message returned by the zxcvbn library
  • score (Number): The score returned by the zxcvbn library. Can be one of 0, 1, 2, 3, 4

By using this callback, we can display a progress bar based on the score to let user know how strong the password is.

Basic example

You can click on the sample password below to see the result.

Common password Is valid?
12345678
admin
abcdef
password
qwerty
Female names Is valid?
mary
patricia
linda
barbara
elizabeth
Male names Is valid?
james
john
robert
michael
william
Surnames Is valid?
smith
johnson
williams
jones
brown
English words on Wikipedia Is valid?
national
university
people
history
county

Changelog

  • v1.5.0: First release. It means that the PasswordStrength plugin requires FormValidation v1.5.0 or newer.