Skip to content

Commit f33ecd6

Browse files
committed
Publish
1 parent 168138f commit f33ecd6

File tree

5 files changed

+210
-37
lines changed

5 files changed

+210
-37
lines changed

.gitignore

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
# Logs
2-
logs
3-
*.log
4-
npm-debug.log*
5-
6-
# Runtime data
7-
pids
8-
*.pid
9-
*.seed
10-
11-
# Directory for instrumented libs generated by jscoverage/JSCover
12-
lib-cov
13-
14-
# Coverage directory used by tools like istanbul
15-
coverage
16-
17-
# nyc test coverage
18-
.nyc_output
19-
20-
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
21-
.grunt
22-
23-
# node-waf configuration
24-
.lock-wscript
25-
26-
# Compiled binary addons (http://nodejs.org/api/addons.html)
27-
build/Release
28-
29-
# Dependency directories
301
node_modules
31-
jspm_packages
32-
33-
# Optional npm cache directory
34-
.npm
35-
36-
# Optional REPL history
37-
.node_repl_history
2+
dist
3+
yarn.lock

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,18 @@
11
# password-complexity
2-
Check password complexity lightly.
2+
A light weight password complexity evaluator
3+
4+
## Install
5+
```
6+
$ npm install password-complexify
7+
```
8+
9+
## Usage
10+
``` javascript
11+
const evaluateComplexity = require('password-complexify');
12+
13+
evaluateComplexity('password');
14+
```
15+
16+
## License
17+
MIT
18+
Based on jquery.complexify.js, copyright Dan Palmer.

package.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "password-complexify",
3+
"description": "A light weight password complexity evaluator",
4+
"main": "./src/password-complexify.js",
5+
"repository": {
6+
"type": "git",
7+
"url": "git+https://github.com/HyunSeob/password-complexify.git"
8+
},
9+
"keywords": [
10+
"password",
11+
"password complexity",
12+
"password strength",
13+
"zxcvbn"
14+
],
15+
"author": "HyunSeob <sytte1017@gmail.com> (http://hyunseob.github.io)",
16+
"license": "MIT",
17+
"bugs": {
18+
"url": "https://github.com/HyunSeob/password-complexify/issues"
19+
},
20+
"homepage": "https://github.com/HyunSeob/password-complexify"
21+
}

src/password-complexify.js

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
/*
2+
* Based on jquery.complexify.js, copyright Dan Palmer.
3+
*/
4+
5+
/*
6+
Generated from 500 worst passwords and 401 banned twiiter passwords as of 20150520.
7+
@source http://www.skullsecurity.org/wiki/index.php/Passwords
8+
9+
Filtered to remove any passwords shorter than 4 characters, as these will cause
10+
unwanted behaviour when in strict banning mode.
11+
*/
12+
13+
const bannedList = '000000|111111|11111111|112233|121212|123123|123456|1234567|12345678|123456789|131313|232323|654321|666666|696969|777777|7777777|8675309|987654|nnnnnn|nop123|nopqrs|noteglh|npprff|npprff14|npgvba|nyoreg|nyoregb|nyrkvf|nyrwnaqen|nyrwnaqeb|nznaqn|nzngrhe|nzrevpn|naqern|naqerj|natryn|natryf|navzny|nagubal|ncbyyb|nccyrf|nefrany|neguhe|nfqstu|nfuyrl|nffubyr|nhthfg|nhfgva|onqobl|onvyrl|onanan|onearl|onfronyy|ongzna|orngevm|ornire|ornivf|ovtpbpx|ovtqnqql|ovtqvpx|ovtqbt|ovtgvgf|oveqvr|ovgpurf|ovgrzr|oynmre|oybaqr|oybaqrf|oybjwbo|oybjzr|obaq007|obavgn|obaavr|obbobb|obbtre|obbzre|obfgba|oenaqba|oenaql|oenirf|oenmvy|oebapb|oebapbf|ohyyqbt|ohfgre|ohggre|ohggurnq|pnyiva|pnzneb|pnzreba|pnanqn|pncgnva|pneybf|pnegre|pnfcre|puneyrf|puneyvr|purrfr|puryfrn|purfgre|puvpntb|puvpxra|pbpnpbyn|pbssrr|pbyyrtr|pbzcnd|pbzchgre|pbafhzre|pbbxvr|pbbcre|pbeirggr|pbjobl|pbjoblf|pelfgny|phzzvat|phzfubg|qnxbgn|qnyynf|qnavry|qnavryyr|qroovr|qraavf|qvnoyb|qvnzbaq|qbpgbe|qbttvr|qbycuva|qbycuvaf|qbanyq|qentba|qernzf|qevire|rntyr1|rntyrf|rqjneq|rvafgrva|rebgvp|rfgeryyn|rkgerzr|snypba|sraqre|sreenev|sveroveq|svfuvat|sybevqn|sybjre|sylref|sbbgonyy|sberire|serqql|serrqbz|shpxrq|shpxre|shpxvat|shpxzr|shpxlbh|tnaqnys|tngrjnl|tngbef|trzvav|trbetr|tvnagf|tvatre|tvmzbqb|tbyqra|tbysre|tbeqba|tertbel|thvgne|thaare|unzzre|unaanu|uneqpber|uneyrl|urngure|uryczr|uragnv|ubpxrl|ubbgref|ubearl|ubgqbt|uhagre|uhagvat|vprzna|vybirlbh|vagrearg|vjnagh|wnpxvr|wnpxfba|wnthne|wnfzvar|wnfcre|wraavsre|wrerzl|wrffvpn|wbuaal|wbuafba|wbeqna|wbfrcu|wbfuhn|whavbe|whfgva|xvyyre|xavtug|ynqvrf|ynxref|ynhera|yrngure|yrtraq|yrgzrva|yvggyr|ybaqba|ybiref|znqqbt|znqvfba|znttvr|zntahz|znevar|znevcbfn|zneyobeb|znegva|zneiva|znfgre|zngevk|znggurj|znirevpx|znkjryy|zryvffn|zrzore|zreprqrf|zreyva|zvpunry|zvpuryyr|zvpxrl|zvqavtug|zvyyre|zvfgerff|zbavpn|zbaxrl|zbafgre|zbetna|zbgure|zbhagnva|zhssva|zhecul|zhfgnat|anxrq|anfpne|anguna|anhtugl|app1701|arjlbex|avpubynf|avpbyr|avccyr|avccyrf|byvire|benatr|cnpxref|cnagure|cnagvrf|cnexre|cnffjbeq|cnffjbeq1|cnffjbeq12|cnffjbeq123|cngevpx|crnpurf|crnahg|crccre|cunagbz|cubravk|cynlre|cyrnfr|cbbxvr|cbefpur|cevapr|cevaprff|cevingr|checyr|chffvrf|dnmjfk|djregl|djreglhv|enoovg|enpury|enpvat|envqref|envaobj|enatre|enatref|erorppn|erqfxvaf|erqfbk|erqjvatf|evpuneq|eboreg|eboregb|ebpxrg|ebfrohq|ehaare|ehfu2112|ehffvn|fnznagun|fnzzl|fnzfba|fnaqen|fnghea|fpbbol|fpbbgre|fpbecvb|fpbecvba|fronfgvna|frperg|frkfrk|funqbj|funaaba|funirq|fvreen|fvyire|fxvccl|fynlre|fzbxrl|fabbcl|fbppre|fbcuvr|fcnaxl|fcnexl|fcvqre|fdhveg|fevavinf|fgnegerx|fgnejnef|fgrryref|fgrira|fgvpxl|fghcvq|fhpprff|fhpxvg|fhzzre|fhafuvar|fhcrezna|fhesre|fjvzzvat|flqarl|grdhvreb|gnlybe|graavf|grerfn|grfgre|grfgvat|gurzna|gubznf|guhaqre|guk1138|gvssnal|gvtref|gvttre|gbzpng|gbctha|gblbgn|genivf|gebhoyr|gehfgab1|ghpxre|ghegyr|gjvggre|havgrq|intvan|ivpgbe|ivpgbevn|ivxvat|ibbqbb|iblntre|jnygre|jneevbe|jrypbzr|jungrire|jvyyvnz|jvyyvr|jvyfba|jvaare|jvafgba|jvagre|jvmneq|knivre|kkkkkk|kkkkkkkk|lnznun|lnaxrr|lnaxrrf|lryybj|mkpioa|mkpioaz|mmmmmm|password|1234|pussy|12345|dragon|qwerty|mustang|letmein|baseball|master|michael|football|shadow|monkey|abc123|pass|fuckme|6969|jordan|harley|ranger|iwantu|jennifer|hunter|fuck|2000|test|batman|trustno1|thomas|tigger|robert|access|love|buster|soccer|hockey|killer|george|sexy|andrew|charlie|superman|asshole|fuckyou|dallas|jessica|panties|pepper|1111|austin|william|daniel|golfer|summer|heather|hammer|yankees|joshua|maggie|biteme|enter|ashley|thunder|cowboy|silver|richard|fucker|orange|merlin|michelle|corvette|bigdog|cheese|matthew|patrick|martin|freedom|ginger|blowjob|nicole|sparky|yellow|camaro|secret|dick|falcon|taylor|bitch|hello|scooter|please|porsche|guitar|chelsea|black|diamond|nascar|jackson|cameron|computer|amanda|wizard|xxxxxxxx|money|phoenix|mickey|bailey|knight|iceman|tigers|purple|andrea|horny|dakota|aaaaaa|player|sunshine|morgan|starwars|boomer|cowboys|edward|charles|girls|booboo|coffee|xxxxxx|bulldog|ncc1701|rabbit|peanut|john|johnny|gandalf|spanky|winter|brandy|compaq|carlos|tennis|james|mike|brandon|fender|anthony|blowme|ferrari|cookie|chicken|maverick|chicago|joseph|diablo|sexsex|hardcore|willie|welcome|chris|panther|yamaha|justin|banana|driver|marine|angels|fishing|david|maddog|hooters|wilson|butthead|dennis|fucking|captain|bigdick|chester|smokey|xavier|steven|viking|snoopy|blue|eagles|winner|samantha|house|miller|flower|jack|firebird|butter|united|turtle|steelers|tiffany|zxcvbn|tomcat|golf|bond007|bear|tiger|doctor|gateway|gators|angel|junior|thx1138|porno|badboy|debbie|spider|melissa|booger|1212|flyers|fish|porn|matrix|teens|scooby|jason|walter|cumshot|boston|braves|yankee|lover|barney|victor|tucker|princess|mercedes|5150|doggie|zzzzzz|gunner|horney|bubba|2112|fred|johnson|xxxxx|tits|member|boobs|donald|bigdaddy|bronco|penis|voyager|rangers|birdie|trouble|white|topgun|bigtits|bitches|green|super|qazwsx|magic|lakers|rachel|slayer|scott|2222|asdf|video|london|7777|marlboro|srinivas|internet|action|carter|jasper|monster|teresa|jeremy|bill|crystal|peter|pussies|cock|beer|rocket|theman|oliver|prince|beach|amateur|muffin|redsox|star|testing|shannon|murphy|frank|hannah|dave|eagle1|11111|mother|nathan|raiders|steve|forever|angela|viper|ou812|jake|lovers|suckit|gregory|buddy|whatever|young|nicholas|lucky|helpme|jackie|monica|midnight|college|baby|cunt|brian|mark|startrek|sierra|leather|4444|beavis|bigcock|happy|sophie|ladies|naughty|giants|booty|blonde|fucked|golden|fire|sandra|pookie|packers|einstein|dolphins|chevy|winston|warrior|sammy|slut|zxcvbnm|nipples|power|victoria|asdfgh|vagina|toyota|travis|hotdog|paris|rock|xxxx|extreme|redskins|erotic|dirty|ford|freddy|arsenal|access14|wolf|nipple|iloveyou|alex|florida|eric|legend|movie|success|rosebud|jaguar|great|cool|cooper|1313|scorpio|mountain|madison|brazil|lauren|japan|naked|squirt|stars|apple|alexis|aaaa|bonnie|peaches|jasmine|kevin|matt|qwertyui|danielle|beaver|4321|4128|runner|swimming|dolphin|gordon|casper|stupid|shit|saturn|gemini|apples|august|3333|canada|blazer|cumming|hunting|kitty|rainbow|arthur|cream|calvin|shaved|surfer|samson|kelly|paul|mine|king|racing|5555|eagle|hentai|newyork|little|redwings|smith|sticky|cocacola|animal|broncos|private|skippy|marvin|blondes|enjoy|girl|apollo|parker|qwert|time|sydney|women|voodoo|magnum|juice|abgrtyu|dreams|maxwell|music|rush2112|russia|scorpion|rebecca|tester|mistress|phantom|billy|6666|albert|abcdef|password1|password12|password123|twitter'.split('|');
14+
15+
const MIN_COMPLEXIFY = 49;
16+
const MAX_COMPLEXIFY = 120;
17+
18+
const CHARSETS = [
19+
// Commonly Used
20+
////////////////////
21+
[0x0020, 0x0020], // Space
22+
[0x0030, 0x0039], // Numbers
23+
[0x0041, 0x005A], // Uppercase
24+
[0x0061, 0x007A], // Lowercase
25+
[0x0021, 0x002F], // Punctuation
26+
[0x003A, 0x0040], // Punctuation
27+
[0x005B, 0x0060], // Punctuation
28+
[0x007B, 0x007E], // Punctuation
29+
// Everything Else
30+
////////////////////
31+
[0x0080, 0x00FF], // Latin-1 Supplement
32+
[0x0100, 0x017F], // Latin Extended-A
33+
[0x0180, 0x024F], // Latin Extended-B
34+
[0x0250, 0x02AF], // IPA Extensions
35+
[0x02B0, 0x02FF], // Spacing Modifier Letters
36+
[0x0300, 0x036F], // Combining Diacritical Marks
37+
[0x0370, 0x03FF], // Greek
38+
[0x0400, 0x04FF], // Cyrillic
39+
[0x0530, 0x058F], // Armenian
40+
[0x0590, 0x05FF], // Hebrew
41+
[0x0600, 0x06FF], // Arabic
42+
[0x0700, 0x074F], // Syriac
43+
[0x0780, 0x07BF], // Thaana
44+
[0x0900, 0x097F], // Devanagari
45+
[0x0980, 0x09FF], // Bengali
46+
[0x0A00, 0x0A7F], // Gurmukhi
47+
[0x0A80, 0x0AFF], // Gujarati
48+
[0x0B00, 0x0B7F], // Oriya
49+
[0x0B80, 0x0BFF], // Tamil
50+
[0x0C00, 0x0C7F], // Telugu
51+
[0x0C80, 0x0CFF], // Kannada
52+
[0x0D00, 0x0D7F], // Malayalam
53+
[0x0D80, 0x0DFF], // Sinhala
54+
[0x0E00, 0x0E7F], // Thai
55+
[0x0E80, 0x0EFF], // Lao
56+
[0x0F00, 0x0FFF], // Tibetan
57+
[0x1000, 0x109F], // Myanmar
58+
[0x10A0, 0x10FF], // Georgian
59+
[0x1100, 0x11FF], // Hangul Jamo
60+
[0x1200, 0x137F], // Ethiopic
61+
[0x13A0, 0x13FF], // Cherokee
62+
[0x1400, 0x167F], // Unified Canadian Aboriginal Syllabics
63+
[0x1680, 0x169F], // Ogham
64+
[0x16A0, 0x16FF], // Runic
65+
[0x1780, 0x17FF], // Khmer
66+
[0x1800, 0x18AF], // Mongolian
67+
[0x1E00, 0x1EFF], // Latin Extended Additional
68+
[0x1F00, 0x1FFF], // Greek Extended
69+
[0x2000, 0x206F], // General Punctuation
70+
[0x2070, 0x209F], // Superscripts and Subscripts
71+
[0x20A0, 0x20CF], // Currency Symbols
72+
[0x20D0, 0x20FF], // Combining Marks for Symbols
73+
[0x2100, 0x214F], // Letterlike Symbols
74+
[0x2150, 0x218F], // Number Forms
75+
[0x2190, 0x21FF], // Arrows
76+
[0x2200, 0x22FF], // Mathematical Operators
77+
[0x2300, 0x23FF], // Miscellaneous Technical
78+
[0x2400, 0x243F], // Control Pictures
79+
[0x2440, 0x245F], // Optical Character Recognition
80+
[0x2460, 0x24FF], // Enclosed Alphanumerics
81+
[0x2500, 0x257F], // Box Drawing
82+
[0x2580, 0x259F], // Block Elements
83+
[0x25A0, 0x25FF], // Geometric Shapes
84+
[0x2600, 0x26FF], // Miscellaneous Symbols
85+
[0x2700, 0x27BF], // Dingbats
86+
[0x2800, 0x28FF], // Braille Patterns
87+
[0x2E80, 0x2EFF], // CJK Radicals Supplement
88+
[0x2F00, 0x2FDF], // Kangxi Radicals
89+
[0x2FF0, 0x2FFF], // Ideographic Description Characters
90+
[0x3000, 0x303F], // CJK Symbols and Punctuation
91+
[0x3040, 0x309F], // Hiragana
92+
[0x30A0, 0x30FF], // Katakana
93+
[0x3100, 0x312F], // Bopomofo
94+
[0x3130, 0x318F], // Hangul Compatibility Jamo
95+
[0x3190, 0x319F], // Kanbun
96+
[0x31A0, 0x31BF], // Bopomofo Extended
97+
[0x3200, 0x32FF], // Enclosed CJK Letters and Months
98+
[0x3300, 0x33FF], // CJK Compatibility
99+
[0x3400, 0x4DB5], // CJK Unified Ideographs Extension A
100+
[0x4E00, 0x9FFF], // CJK Unified Ideographs
101+
[0xA000, 0xA48F], // Yi Syllables
102+
[0xA490, 0xA4CF], // Yi Radicals
103+
[0xAC00, 0xD7A3], // Hangul Syllables
104+
[0xD800, 0xDB7F], // High Surrogates
105+
[0xDB80, 0xDBFF], // High Private Use Surrogates
106+
[0xDC00, 0xDFFF], // Low Surrogates
107+
[0xE000, 0xF8FF], // Private Use
108+
[0xF900, 0xFAFF], // CJK Compatibility Ideographs
109+
[0xFB00, 0xFB4F], // Alphabetic Presentation Forms
110+
[0xFB50, 0xFDFF], // Arabic Presentation Forms-A
111+
[0xFE20, 0xFE2F], // Combining Half Marks
112+
[0xFE30, 0xFE4F], // CJK Compatibility Forms
113+
[0xFE50, 0xFE6F], // Small Form Variants
114+
[0xFE70, 0xFEFE], // Arabic Presentation Forms-B
115+
[0xFEFF, 0xFEFF], // Specials
116+
[0xFF00, 0xFFEF], // Halfwidth and Fullwidth Forms
117+
[0xFFF0, 0xFFFD] // Specials
118+
];
119+
120+
/**
121+
* Get complexity score from string and character pair.
122+
*
123+
* @private
124+
* @param {string} string to be evaluated.
125+
* @param {Array} character pair
126+
* @returns {number} complexity score.
127+
*/
128+
function additionalComplexityForCharset(str, charset) {
129+
return str.split('')
130+
.map(v => v.charCodeAt(0))
131+
.filter(v => (charset[0] <= v) && (v <= charset[1]))
132+
.length
133+
? (charset[1] - charset[0] + 1)
134+
: 0;
135+
}
136+
137+
/**
138+
* Get complexity score from given password.
139+
*
140+
* @static
141+
* @param {string} password A password to be evaluated.
142+
* @returns {number} complexity A complexity of given password.
143+
* @example
144+
*
145+
* var password = '12345678';
146+
* evaluateComplexity(password);
147+
*/
148+
module.exports = function evaluateComplexity(password) {
149+
if (bannedList.includes(password.toLowerCase())) return 1;
150+
151+
return Math.log(Math.pow(CHARSETS.reduce((score, charset) => {
152+
return score + additionalComplexityForCharset(password, charset);
153+
}, 0), password.length));
154+
};

test/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const assert = require('assert');
2+
const evaluateComplexity = require('../src/password-complexify.js')
3+
4+
5+
const empty = evaluateComplexity('');
6+
const banned = evaluateComplexity('qwerty');
7+
const numberOnly = evaluateComplexity('38563936');
8+
const alphabetOnly = evaluateComplexity('iefwondi');
9+
const common = evaluateComplexity('complex1017');
10+
const strong = evaluateComplexity('c0mp!ex1o1&');
11+
12+
assert.equal(empty, 0);
13+
assert.equal(banned, 1);
14+
assert.ok(numberOnly < alphabetOnly);
15+
assert.ok(alphabetOnly < common);
16+
assert.ok(common < strong);

0 commit comments

Comments
 (0)