From 2579987fda90378a0ef71e3a5e8cc61741f2125e Mon Sep 17 00:00:00 2001 From: Pieter Wigboldus Date: Fri, 10 Nov 2017 15:48:27 +0100 Subject: [PATCH] Dont load typo twice if you use a custom dictionary --- dist/js/app.js | 6 ++++-- dist/js/app.js.map | 2 +- js/is_strong_password.js | 6 ++++-- package-lock.json | 2 +- package.json | 2 +- 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dist/js/app.js b/dist/js/app.js index 9b1e277..77bd0a9 100644 --- a/dist/js/app.js +++ b/dist/js/app.js @@ -52,7 +52,7 @@ var StrongPassword = function () { this.dictionaries = params.dictionaries || false; - this.version = '1.1.1'; + this.version = '1.1.2'; results = this.check(); this.strong = results.strong; @@ -72,12 +72,14 @@ var StrongPassword = function () { var strong = true; var reasonText = void 0; var notRealWords = []; - var dictionary = new Typo(this.locale); + var dictionary = void 0; if (this.dictionaries) { dictionary = new Typo(this.locale, false, false, { dictionaryPath: this.dictionaries }); + } else { + dictionary = new Typo(this.locale); } if (!this.password) { diff --git a/dist/js/app.js.map b/dist/js/app.js.map index b82641d..e3ba485 100644 --- a/dist/js/app.js.map +++ b/dist/js/app.js.map @@ -1 +1 @@ -{"version":3,"sources":["is_strong_password.js"],"names":["Typo","require","StrongPassword","params","results","strong","reasonText","locale","password","minimumLength","minimumWords","mustHaveNumbers","numbers","mustHaveLowerCase","lowercase","mustHaveUpperCase","uppercase","dictionaries","version","check","reason","notRealWords","dictionary","dictionaryPath","length","split","match","forEach","value","cleanValue","replace","Number","isInteger","push","join","module","exports"],"mappings":";;;;;;;;AAAA,IAAMA,OAAO,OAAOC,OAAP,IAAkB,WAAlB,GAAgCA,QAAQ,SAAR,CAAhC,GAAqDD,IAAlE;;AAEA;;;;IAGME;AACF;;;;;AAKA,4BAAYC,MAAZ,EAAoB;AAAA;;AAChB,YAAIC,gBAAJ;;AAEA,aAAKC,MAAL,GAAc,KAAd;;AAEA,YAAI,CAACF,MAAL,EAAa;AACT,iBAAKG,UAAL,GA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zBlB,6BAAa,gCAAiCe,aAAaa,IAAb,CAAkB,IAAlB,CAAjC,GAA4D,GAAzE;AACA7B,yBAAS,KAAT;AACH;;AAED,mBAAO;AACHA,wBAAQA,MADL;AAEHe,wBAAQd;AAFL,aAAP;AAIH;;AAED;;;;;;;;4BAKe;AACX,mBAAO,KAAKD,MAAZ;AACH;;AAED;;;;;;;;4BAKa;AACT,mBAAO,KAAKC,UAAZ;AACH;;;;;;AAGL,IAAI,QAAO6B,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8B,QAAOA,OAAOC,OAAd,MAA0B,QAA5D,EAAsE;AAClED,WAAOC,OAAP,GAAiBlC,cAAjB;AACH","file":"app.js","sourcesContent":["const Typo = typeof require != 'undefined' ? require('typo-js') : Typo;\n\n/**\n * Strong password validation.\n */\nclass StrongPassword {\n /**\n * Contructor.\n *\n * @param {object} params\n */\n constructor(params) {\n let results;\n\n this.strong = false;\n\n if (!params) {\n this.reasonText = 'no params';\n\n return;\n }\n\n this.locale = params.locale || 'en_US';\n this.password = params.password;\n this.minimumLength = params.minimumLength || 10;\n this.minimumWords = params.minimumWords || 4;\n this.mustHaveNumbers = true;\n if (typeof params.numbers == 'boolean') {\n this.mustHaveNumbers = params.numbers;\n }\n\n this.mustHaveLowerCase = true;\n if (typeof params.lowercase == 'boolean') {\n this.mustHaveLowerCase = params.lowercase;\n }\n\n this.mustHaveUpperCase = true;\n if (typeof params.uppercase == 'boolean') {\n this.mustHaveUpperCase = params.uppercase;\n }\n\n this.dictionaries = params.dictionaries || false;\n\n this.version = '1.1.1';\n\n results = this.check();\n this.strong = results.strong;\n this.reasonText = results.reason;\n }\n\n /**\n * Check if the password is strong.\n *\n * @return {boolean}\n */\n check() {\n let strong = true;\n let reasonText;\n let notRealWords = [];\n let dictionary = new Typo(this.locale);\n\n if (this.dictionaries) {\n dictionary = new Typo(this.locale, false, false, {\n dictionaryPath: this.dictionaries\n });\n }\n\n if (!this.password) {\n return {\n strong: false,\n reason: 'empty'\n };\n }\n\n if (this.password.length < this.minimumLength) {\n return {\n strong: false,\n reason: 'to short'\n };\n }\n\n if (this.password.split(' ').length < this.minimumWords) {\n return {\n strong: false,\n reason: 'too few words'\n };\n }\n\n if (this.mustHaveNumbers && !this.password.match(/\\d+/g)) {\n return {\n strong: false,\n reason: 'has no numbers'\n };\n }\n\n if (this.mustHaveLowerCase && !this.password.match(/[a-z]/g)) {\n return {\n strong: false,\n reason: 'has no alphabet chars'\n };\n }\n\n if (this.mustHaveUpperCase && !this.password.match(/[A-Z]/g)) {\n return {\n strong: false,\n reason: 'has no uppercase alphabet chars'\n };\n }\n\n this.password.split(' ').forEach(function(value) {\n var cleanValue = value.replace(/[,.?!]/g, '');\n\n if (!dictionary.check(cleanValue) && !Number.isInteger(cleanValue * 1)) {\n notRealWords.push(value);\n }\n });\n\n if (notRealWords.length > 0) {\n reasonText = 'doesnt has a real word(s) [' + (notRealWords.join(', ')) + ']';\n strong = false;\n }\n\n return {\n strong: strong,\n reason: reasonText\n };\n }\n\n /**\n * Return if the password is strong.\n *\n * @return {boolean}\n */\n get isStrong() {\n return this.strong;\n }\n\n /**\n * Return the reason if the password is not strong.\n *\n * @return {boolean}\n */\n get reason() {\n return this.reasonText;\n }\n}\n\nif (typeof module === 'object' && typeof module.exports === 'object') {\n module.exports = StrongPassword;\n}\n"]} \ No newline at end of file +{"version":3,"sources":["is_strong_password.js"],"names":["Typo","require","StrongPassword","params","results","strong","reasonText","locale","password","minimumLength","minimumWords","mustHaveNumbers","numbers","mustHaveLowerCase","lowercase","mustHaveUpperCase","uppercase","dictionaries","version","check","reason","notRealWords","dictionary","dictionaryPath","length","split","match","forEach","value","cleanValue","replace","Number","isInteger","push","join","module","exports"],"mappings":";;;;;;;;AAAA,IAAMA,OAAO,OAAOC,OAAP,IAAkB,WAAlB,GAAgCA,QAAQ,SAAR,CAAhC,GAAqDD,IAAlE;;AAEA;;;;IAGME;AACF;;;;;AAKA,4BAAYC,MAAZ,EAAoB;AAAA;;A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iBH,aAAa,CAA9B,CAAtC,EAAwE;AACpER,iCAAaY,IAAb,CAAkBL,KAAlB;AACH;AACJ,aAND;;AAQA,gBAAIP,aAAaG,MAAb,GAAsB,CAA1B,EAA6B;AACzBlB,6BAAa,gCAAiCe,aAAaa,IAAb,CAAkB,IAAlB,CAAjC,GAA4D,GAAzE;AACA7B,yBAAS,KAAT;AACH;;AAED,mBAAO;AACHA,wBAAQA,MADL;AAEHe,wBAAQd;AAFL,aAAP;AAIH;;AAED;;;;;;;;4BAKe;AACX,mBAAO,KAAKD,MAAZ;AACH;;AAED;;;;;;;;4BAKa;AACT,mBAAO,KAAKC,UAAZ;AACH;;;;;;AAGL,IAAI,QAAO6B,MAAP,yCAAOA,MAAP,OAAkB,QAAlB,IAA8B,QAAOA,OAAOC,OAAd,MAA0B,QAA5D,EAAsE;AAClED,WAAOC,OAAP,GAAiBlC,cAAjB;AACH","file":"app.js","sourcesContent":["const Typo = typeof require != 'undefined' ? require('typo-js') : Typo;\n\n/**\n * Strong password validation.\n */\nclass StrongPassword {\n /**\n * Contructor.\n *\n * @param {object} params\n */\n constructor(params) {\n let results;\n\n this.strong = false;\n\n if (!params) {\n this.reasonText = 'no params';\n\n return;\n }\n\n this.locale = params.locale || 'en_US';\n this.password = params.password;\n this.minimumLength = params.minimumLength || 10;\n this.minimumWords = params.minimumWords || 4;\n this.mustHaveNumbers = true;\n if (typeof params.numbers == 'boolean') {\n this.mustHaveNumbers = params.numbers;\n }\n\n this.mustHaveLowerCase = true;\n if (typeof params.lowercase == 'boolean') {\n this.mustHaveLowerCase = params.lowercase;\n }\n\n this.mustHaveUpperCase = true;\n if (typeof params.uppercase == 'boolean') {\n this.mustHaveUpperCase = params.uppercase;\n }\n\n this.dictionaries = params.dictionaries || false;\n\n this.version = '1.1.2';\n\n results = this.check();\n this.strong = results.strong;\n this.reasonText = results.reason;\n }\n\n /**\n * Check if the password is strong.\n *\n * @return {boolean}\n */\n check() {\n let strong = true;\n let reasonText;\n let notRealWords = [];\n let dictionary;\n\n if (this.dictionaries) {\n dictionary = new Typo(this.locale, false, false, {\n dictionaryPath: this.dictionaries\n });\n } else {\n dictionary = new Typo(this.locale);\n }\n\n if (!this.password) {\n return {\n strong: false,\n reason: 'empty'\n };\n }\n\n if (this.password.length < this.minimumLength) {\n return {\n strong: false,\n reason: 'to short'\n };\n }\n\n if (this.password.split(' ').length < this.minimumWords) {\n return {\n strong: false,\n reason: 'too few words'\n };\n }\n\n if (this.mustHaveNumbers && !this.password.match(/\\d+/g)) {\n return {\n strong: false,\n reason: 'has no numbers'\n };\n }\n\n if (this.mustHaveLowerCase && !this.password.match(/[a-z]/g)) {\n return {\n strong: false,\n reason: 'has no alphabet chars'\n };\n }\n\n if (this.mustHaveUpperCase && !this.password.match(/[A-Z]/g)) {\n return {\n strong: false,\n reason: 'has no uppercase alphabet chars'\n };\n }\n\n this.password.split(' ').forEach(function(value) {\n var cleanValue = value.replace(/[,.?!]/g, '');\n\n if (!dictionary.check(cleanValue) && !Number.isInteger(cleanValue * 1)) {\n notRealWords.push(value);\n }\n });\n\n if (notRealWords.length > 0) {\n reasonText = 'doesnt has a real word(s) [' + (notRealWords.join(', ')) + ']';\n strong = false;\n }\n\n return {\n strong: strong,\n reason: reasonText\n };\n }\n\n /**\n * Return if the password is strong.\n *\n * @return {boolean}\n */\n get isStrong() {\n return this.strong;\n }\n\n /**\n * Return the reason if the password is not strong.\n *\n * @return {boolean}\n */\n get reason() {\n return this.reasonText;\n }\n}\n\nif (typeof module === 'object' && typeof module.exports === 'object') {\n module.exports = StrongPassword;\n}\n"]} \ No newline at end of file diff --git a/js/is_strong_password.js b/js/is_strong_password.js index f9678da..306878a 100644 --- a/js/is_strong_password.js +++ b/js/is_strong_password.js @@ -41,7 +41,7 @@ class StrongPassword { this.dictionaries = params.dictionaries || false; - this.version = '1.1.1'; + this.version = '1.1.2'; results = this.check(); this.strong = results.strong; @@ -57,12 +57,14 @@ class StrongPassword { let strong = true; let reasonText; let notRealWords = []; - let dictionary = new Typo(this.locale); + let dictionary; if (this.dictionaries) { dictionary = new Typo(this.locale, false, false, { dictionaryPath: this.dictionaries }); + } else { + dictionary = new Typo(this.locale); } if (!this.password) { diff --git a/package-lock.json b/package-lock.json index 45e0029..ccdbf95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "strongpassword", - "version": "1.1.1", + "version": "1.1.2", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index da6ec82..16ed36c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "strongpassword", - "version": "1.1.1", + "version": "1.1.2", "description": "Check if the password is strong.", "main": "js/is_strong_password.js", "files": [