In this example, we will use the awesome Dropbox's zxcvbn library to build a password strength meter.
For anyone who haven't known about zxcvbn library, it's a password strength estimator inspired by password crackers developed by Dropbox.
It can recognize and weighs 30k common passwords. For more information about this library, you can refer to its official page.
It's quite easy to use it to see how strong a given password is:
score is an integer number between 0 and 4 indicate the strength level:
|Score ||Description |
|0 ||Too guessable: risky password |
|1 ||Very guessable: protection from throttled online attacks |
|2 ||Somewhat guessable: protection from unthrottled online attacks |
|3 ||Safely unguessable: moderate protection from offline slow-hash scenario |
|4 ||Very unguessable: strong protection from offline slow-hash scenario |
We will use the callback validator to check the password strength, and treat it as an invalid password if the score is less than 3:
The sample code above shows how to set a dynamic error message returned from the callback
validator. This capability is also available in a few of validators as listed in the dynamic message
We also can use Bootstrap's progress bar component to show the strength level:
If you use any framework which is supported by FormValidation, you can use the framework progress bar component as listed in the table below:
Lastly, for a full working demonstration, you can play with the following form: