- Notifications
You must be signed in to change notification settings - Fork3
nosco/password-checker
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
The checker works out of the box, but will accept any password.
You need to enable rules and change the words lists, if you don't want to use the defaults.
varChecker=require('password-checker');varchecker=newChecker();
// Change minimum length required// Default is: 0, which is effectively disabling of the checkchecker.min_length=8;// Change maximum length required// Default is: 0, which is effectively disabling of the checkchecker.max_length=120;
checker.requireLetters(true);checker.requireNumbers(true);checker.requireSymbols(true);
checker.requireLetters(true);checker.requireNumbersOrSymbols(true);
checker.checkLetters(true);checker.checkNumbers(true);checker.checkSymbols(true);
Names, words and passwords checks works the same way.They can tak up to 3 parameters.
// Disallow passwords that matches a full namechecker.disallowNames(true);// Disallow passwords that contains word(s) found in the words listchecker.disallowWords(true,true);// Disallow passwords that contains password(s) found in the passwords list// But limit it to passwords with 3 or more characterschecker.disallowPasswords(true,true,3);
// Change the letters that are allowed// Default is: ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzchecker.allowed_letters='ABCDEFGHJKLMNPQRSTUVWXYZabcdefghkmnpqrstuvwxyz';// Default is: 0123456789checker.allowed_numbers='23456789';// Default is: _- !\"?$%^&*()+={}[]:;@'~#|<>,.?\\/checker.allowed_symbols='_-';
The words will always be changed to lowercase and so will the actual passwords checked.
checker.disallowed_words=['some','Others'];checker.disallowed_names=['Dan','joe'];checker.disallowed_passwords=['ABCDEF','hijklm'];
Each check will return true or false.
The checker will then hold a list of errors that occurred.
A list of rules and whether they failed will also be accessible.
checker.min_length=10;console.log(checker.check('Should work'));// Prints:// trueconsole.log(checker.errors);// Prints:// []console.log(checker.rules);// Prints:// { min_length:// { name: 'min_length',// method: [Function],// error_message: null,// failed: false}}
checker.min_length=100;console.log(checker.check('Should not work'));// Prints:// falseconsole.log(checker.errors);// Prints:// [ [Error: The password is too short] ]console.log(checker.rules);// Prints:// { min_length:// { name: 'min_length',// method: [Function],// error_message: 'The password is too short',// failed: true}}
The words list is the first 10.000 words found in a list of 1/3 million words list.
The 1/3 million list is create by Peter Norvig who is Director of Research @ Google.
The entire list can be found here:Natural Language Corpus Data: Beautiful Data - the file is calledcount_1w.txt
Thank you Peter Norvig!
The names list is a mashup of different sources and contains 17956 common international names:
US Names from the US Social Security
"Given names" extracted from WikiPedia
International names extracted from Baby Name Wizard
Thank you US Social Security, WikiPedia and Baby Name Wizard!
Passwords is a list of the 10.000 most used passwords according to Mark Burnett fromxato.net.
You can find the list (+1 with frequency) inthis blog post by Mark Burnett.
Thank you Mark Burnett!