Gathering detailed insights and metrics for zxcvbn
Gathering detailed insights and metrics for zxcvbn
Gathering detailed insights and metrics for zxcvbn
Gathering detailed insights and metrics for zxcvbn
npm install zxcvbn
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
15,164 Stars
379 Commits
946 Forks
265 Watching
2 Branches
49 Contributors
Updated on 28 Nov 2024
CoffeeScript (97.9%)
Python (2.1%)
Cumulative downloads
Total Downloads
Last day
-14.1%
103,089
Compared to previous day
Last week
3.6%
600,834
Compared to previous week
Last month
14%
2,507,069
Compared to previous month
Last year
5.8%
26,707,040
Compared to previous year
_________________________________________________/\/\___________________
_/\/\/\/\/\__/\/\__/\/\____/\/\/\/\__/\/\__/\/\__/\/\________/\/\/\/\___
_____/\/\______/\/\/\____/\/\________/\/\__/\/\__/\/\/\/\____/\/\__/\/\_
___/\/\________/\/\/\____/\/\__________/\/\/\____/\/\__/\/\__/\/\__/\/\_
_/\/\/\/\/\__/\/\__/\/\____/\/\/\/\______/\______/\/\/\/\____/\/\__/\/\_
________________________________________________________________________
zxcvbn
is a password strength estimator inspired by password crackers. Through pattern matching and conservative estimation, it recognizes and weighs 30k common passwords, common names and surnames according to US census data, popular English words from Wikipedia and US television and movies, and other common patterns like dates, repeats (aaa
), sequences (abcd
), keyboard patterns (qwertyuiop
), and l33t speak.
Consider using zxcvbn as an algorithmic alternative to password composition policy — it is more secure, flexible, and usable when sites require a minimal complexity score in place of annoying rules like "passwords must contain three of {lower, upper, numbers, symbols}".
P@ssword1
) and disallowing strong passwords.For further detail and motivation, please refer to the USENIX Security '16 paper and presentation.
At Dropbox we use zxcvbn (Release notes) on our web, desktop, iOS and Android clients. If JavaScript doesn't work for you, others have graciously ported the library to these languages:
zxcvbn-python
(Python)zxcvbn-cpp
(C/C++/Python/JS)zxcvbn-c
(C/C++)zxcvbn-rs
(Rust)zxcvbn-go
(Go)zxcvbn4j
(Java)nbvcxz
(Java)zxcvbn-ruby
(Ruby)zxcvbn-js
(Ruby [via ExecJS])zxcvbn-ios
(Objective-C)zxcvbn-cs
(C#/.NET)szxcvbn
(Scala)zxcvbn-php
(PHP)zxcvbn-api
(REST)ocaml-zxcvbn
(OCaml bindings for zxcvbn-c
)Integrations with other frameworks:
angular-zxcvbn
(AngularJS)zxcvbn detects and supports CommonJS (node, browserify) and AMD (RequireJS). In the absence of those, it adds a single function zxcvbn()
to the global namespace.
Install node
and bower
if you haven't already.
Get zxcvbn
:
1cd /path/to/project/root 2bower install zxcvbn
Add this script to your index.html
:
1<script src="bower_components/zxcvbn/dist/zxcvbn.js"> 2</script>
To make sure it loaded properly, open in a browser and type zxcvbn('Tr0ub4dour&3')
into the console.
To pull in updates and bug fixes:
1bower update zxcvbn
zxcvbn works identically on the server.
1$ npm install zxcvbn 2$ node 3> var zxcvbn = require('zxcvbn'); 4> zxcvbn('Tr0ub4dour&3');
Add zxcvbn.js
to your project (using bower, npm or direct download) and import as usual:
1requirejs(["relpath/to/zxcvbn"], function (zxcvbn) { 2 console.log(zxcvbn('Tr0ub4dour&3')); 3});
If you're using npm
and have require('zxcvbn')
somewhere in your code, browserify and webpack should just work.
1$ npm install zxcvbn 2$ echo "console.log(require('zxcvbn'))" > mymodule.js 3$ browserify mymodule.js > browserify_bundle.js 4$ webpack mymodule.js webpack_bundle.js
But we recommend against bundling zxcvbn via tools like browserify and webpack, for three reasons:
zxcvbn()
immediately upon page load; since zxcvbn()
is typically called in response to user events like filling in a password, there's ample time to fetch zxcvbn.js
after initial html/css/js loads and renders.See the performance section below for tips on loading zxcvbn stand-alone.
Tangentially, if you want to build your own standalone, consider tweaking the browserify pipeline used to generate dist/zxcvbn.js
:
1$ browserify --debug --standalone zxcvbn \ 2 -t coffeeify --extension='.coffee' \ 3 -t uglifyify \ 4 src/main.coffee | exorcist dist/zxcvbn.js.map >| dist/zxcvbn.js
--debug
adds an inline source map to the bundle. exorcist
pulls it out into dist/zxcvbn.js.map
.--standalone zxcvbn
exports a global zxcvbn
when CommonJS/AMD isn't detected.-t coffeeify --extension='.coffee'
compiles .coffee
to .js
before bundling. This is convenient as it allows .js
modules to import from .coffee
modules and vice-versa. Instead of this transform, one could also compile everything to .js
first (npm run prepublish
) and point browserify
to lib
instead of src
.-t uglifyify
minifies the bundle through UglifyJS, maintaining proper source mapping.Download zxcvbn.js.
Add to your .html:
1<script type="text/javascript" src="path/to/zxcvbn.js"></script>
try zxcvbn interactively to see these docs in action.
1zxcvbn(password, user_inputs=[])
zxcvbn()
takes one required argument, a password, and returns a result object with several properties:
1result.guesses # estimated guesses needed to crack password 2result.guesses_log10 # order of magnitude of result.guesses 3 4result.crack_times_seconds # dictionary of back-of-the-envelope crack time 5 # estimations, in seconds, based on a few scenarios: 6{ 7 # online attack on a service that ratelimits password auth attempts. 8 online_throttling_100_per_hour 9 10 # online attack on a service that doesn't ratelimit, 11 # or where an attacker has outsmarted ratelimiting. 12 online_no_throttling_10_per_second 13 14 # offline attack. assumes multiple attackers, 15 # proper user-unique salting, and a slow hash function 16 # w/ moderate work factor, such as bcrypt, scrypt, PBKDF2. 17 offline_slow_hashing_1e4_per_second 18 19 # offline attack with user-unique salting but a fast hash 20 # function like SHA-1, SHA-256 or MD5. A wide range of 21 # reasonable numbers anywhere from one billion - one trillion 22 # guesses per second, depending on number of cores and machines. 23 # ballparking at 10B/sec. 24 offline_fast_hashing_1e10_per_second 25} 26 27result.crack_times_display # same keys as result.crack_times_seconds, 28 # with friendlier display string values: 29 # "less than a second", "3 hours", "centuries", etc. 30 31result.score # Integer from 0-4 (useful for implementing a strength bar) 32 33 0 # too guessable: risky password. (guesses < 10^3) 34 35 1 # very guessable: protection from throttled online attacks. (guesses < 10^6) 36 37 2 # somewhat guessable: protection from unthrottled online attacks. (guesses < 10^8) 38 39 3 # safely unguessable: moderate protection from offline slow-hash scenario. (guesses < 10^10) 40 41 4 # very unguessable: strong protection from offline slow-hash scenario. (guesses >= 10^10) 42 43result.feedback # verbal feedback to help choose better passwords. set when score <= 2. 44 45 result.feedback.warning # explains what's wrong, eg. 'this is a top-10 common password'. 46 # not always set -- sometimes an empty string 47 48 result.feedback.suggestions # a possibly-empty list of suggestions to help choose a less 49 # guessable password. eg. 'Add another word or two' 50 51result.sequence # the list of patterns that zxcvbn based the 52 # guess calculation on. 53 54result.calc_time # how long it took zxcvbn to calculate an answer, 55 # in milliseconds.
The optional user_inputs
argument is an array of strings that zxcvbn will treat as an extra dictionary. This can be whatever list of strings you like, but is meant for user inputs from other fields of the form, like name and email. That way a password that includes a user's personal information can be heavily penalized. This list is also good for site-specific vocabulary — Acme Brick Co. might want to include ['acme', 'brick', 'acmebrick', etc].
zxcvbn operates below human perception of delay for most input: ~5-20ms for ~25 char passwords on modern browsers/CPUs, ~100ms for passwords around 100 characters. To bound runtime latency for really long passwords, consider sending zxcvbn()
only the first 100 characters or so of user input.
zxcvbn.js
bundled and minified is about 400kB gzipped or 820kB uncompressed, most of which is dictionaries. Consider these tips if you're noticing page load latency on your site.
Then try one of these alternatives:
Put your <script src="zxcvbn.js">
tag at the end of your html, just before the closing </body>
tag. This ensures your page loads and renders before the browser fetches and loads zxcvbn.js
. The downside with this approach is zxcvbn()
becomes available later than had it been included in <head>
— not an issue on most signup pages where users are filling out other fields first.
If you're using RequireJS, try loading zxcvbn.js
separately from your main bundle. Something to watch out for: if zxcvbn.js
is required inside a keyboard handler waiting for user input, the entire script might be loaded only after the user presses their first key, creating nasty latency. Avoid this by calling your handler once upon page load, independent of user input, such that the requirejs()
call runs earlier.
Use the HTML5 async
script attribute. Downside: doesn't work in IE7-9 or Opera Mini.
Include an inline <script>
in <head>
that asynchronously loads zxcvbn.js
in the background. Advantage over (3): it works in older browsers.
1// cross-browser asynchronous script loading for zxcvbn. 2// adapted from http://friendlybit.com/js/lazy-loading-asyncronous-javascript/ 3 4(function() { 5 6 var ZXCVBN_SRC = 'path/to/zxcvbn.js'; 7 8 var async_load = function() { 9 var first, s; 10 s = document.createElement('script'); 11 s.src = ZXCVBN_SRC; 12 s.type = 'text/javascript'; 13 s.async = true; 14 first = document.getElementsByTagName('script')[0]; 15 return first.parentNode.insertBefore(s, first); 16 }; 17 18 if (window.attachEvent != null) { 19 window.attachEvent('onload', async_load); 20 } else { 21 window.addEventListener('load', async_load, false); 22 } 23 24}).call(this);
Bug reports and pull requests welcome!
1git clone https://github.com/dropbox/zxcvbn.git
zxcvbn is built with CoffeeScript, browserify, and uglify-js. CoffeeScript source lives in src
, which gets compiled, bundled and minified into dist/zxcvbn.js
.
1npm run build # builds dist/zxcvbn.js 2npm run watch # same, but quickly rebuilds as changes are made in src.
For debugging, both build
and watch
output an external source map dist/zxcvbn.js.map
that points back to the original CoffeeScript code.
Two source files, adjacency_graphs.coffee
and frequency_lists.coffee
, are generated by python scripts in data-scripts
that read raw data from the data
directory.
For node developers, in addition to dist
, the zxcvbn npm
module includes a lib
directory (hidden from git) that includes one compiled .js
and .js.map
file for every .coffee
in src
. See prepublish
in package.json
to learn more.
Dropbox for supporting open source!
Mark Burnett for releasing his 10M password corpus and for his 2005 book, Perfect Passwords: Selection, Protection, Authentication.
Wiktionary contributors for building a frequency list of English words as used in television and movies.
Researchers at Concordia University for studying password estimation rigorously and recommending zxcvbn.
And xkcd for the inspiration :+1::horse::battery::heart:
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
Found 9/20 approved changesets -- score normalized to 4
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More