summary refs log tree commit diff
path: root/api/src/util/utility
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-04-11 00:25:53 +1000
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2022-04-11 00:26:33 +1000
commit4304b77987df763a616bfc4387d3884187cf15fd (patch)
tree22e14d0086d60cd01239a94ca3805ccd988a0f38 /api/src/util/utility
parentMerge branch 'master' into fix/claim_accounts (diff)
parentUpdate Guild.ts (diff)
downloadserver-4304b77987df763a616bfc4387d3884187cf15fd.tar.xz
Merge branch 'master' into fix/claim_accounts
Diffstat (limited to 'api/src/util/utility')
-rw-r--r--api/src/util/utility/passwordStrength.ts21
1 files changed, 16 insertions, 5 deletions
diff --git a/api/src/util/utility/passwordStrength.ts b/api/src/util/utility/passwordStrength.ts

index 047df008..e75e48f6 100644 --- a/api/src/util/utility/passwordStrength.ts +++ b/api/src/util/utility/passwordStrength.ts
@@ -13,6 +13,7 @@ const blocklist: string[] = []; // TODO: update ones passwordblocklist is stored * - min <n> numbers * - min <n> symbols * - min <n> uppercase chars + * - shannon entropy divided by password entropy * * Returns: 0 > pw > 1 */ @@ -22,28 +23,38 @@ export function checkPassword(password: string): number { // checks for total password len if (password.length >= minLength - 1) { - strength += 0.25; + strength += 0.05; } // checks for amount of Numbers if (password.count(reNUMBER) >= minNumbers - 1) { - strength += 0.25; + strength += 0.05; } // checks for amount of Uppercase Letters if (password.count(reUPPERCASELETTER) >= minUpperCase - 1) { - strength += 0.25; + strength += 0.05; } // checks for amount of symbols if (password.replace(reSYMBOLS, "").length >= minSymbols - 1) { - strength += 0.25; + strength += 0.05; } // checks if password only consists of numbers or only consists of chars if (password.length == password.count(reNUMBER) || password.length === password.count(reUPPERCASELETTER)) { strength = 0; } - + + let entropyMap; + for (let i = 0; i < password.length; i++) { + if (entropyMap[password[i]]) entropyMap[password[i]]++; + else entropyMap[password[i]] = 1; + } + + let entropies = Array(entropyMap); + + entropies.map(x => (x / entropyMap.length)); + strength += entropies.reduceRight((a, x), a - (x * Math.log2(x))) / Math.log2(password.length); return strength; }