From a36cb17165730b30bdee8b032cec44dd75f7f8e4 Mon Sep 17 00:00:00 2001 From: djmaze Date: Thu, 4 Mar 2021 14:18:23 +0100 Subject: [PATCH] Issue #51 Added: visual password weakness meter Bugfix: PasswordWeaknessCheck --- plugins/change-password/index.php | 2 +- .../js/ChangePasswordUserSettings.js | 35 +++++++++++++++++++ .../templates/SettingsChangePassword.html | 4 ++- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/plugins/change-password/index.php b/plugins/change-password/index.php index 4d88fda42..ee9311c2b 100644 --- a/plugins/change-password/index.php +++ b/plugins/change-password/index.php @@ -194,7 +194,7 @@ class ChangePasswordPlugin extends \RainLoop\Plugins\AbstractPlugin private static function PasswordWeaknessCheck(string $sPassword) : bool { - return !!preg_match('/111|1234|password|abc|qwerty|monkey|letmein|dragon|baseball|iloveyou|trustno1|sunshine|master|welcome|shadow|ashley|football|jesus|michael|ninja|mustang|vkontakte/i', $sPassword); + return !\preg_match('/111|1234|password|abc|qwerty|monkey|letmein|dragon|baseball|iloveyou|trustno1|sunshine|master|welcome|shadow|ashley|football|jesus|michael|ninja|mustang|vkontakte/i', $sPassword); } } diff --git a/plugins/change-password/js/ChangePasswordUserSettings.js b/plugins/change-password/js/ChangePasswordUserSettings.js index 2e1c7b2aa..32995e93c 100644 --- a/plugins/change-password/js/ChangePasswordUserSettings.js +++ b/plugins/change-password/js/ChangePasswordUserSettings.js @@ -6,6 +6,35 @@ return; } + let pw_re = [/[^0-9A-Za-z]+/g, /[0-9]+/g, /[A-Z]+/g, /[a-z]+/g], + getPassStrength = v => { + var m, + i = v.length, + s = i?1:0, + c = 0, + ii = 0; + while (i--) { + if (v[i] != v[i+1]) { + ++s; + } else { + s -= 0.5; + } + } + for (i = 0; i < 4; ++i) { + m = v.match(pw_re[i]); + if (m) { + ++c; + for (; ii < m.length; ++ii) { + if (5 > m[ii].length) { + ++s; + } + } + } + } + s = (s / 3 * c); + return Math.max(0, Math.min(100, s * 5)); + }; + class ChangePasswordUserSettings { constructor() { @@ -68,6 +97,12 @@ current ? this.currentPasswordError(false) : this.passwordMismatch(false); } + onBuild(dom) { + let input = dom.querySelector('.new-password'), + meter = dom.querySelector('.new-password-meter'); + input && meter && input.addEventListener('input',() => meter.value = getPassStrength(input.value)); + } + onHide() { this.reset(false); this.currentPassword(''); diff --git a/plugins/change-password/templates/SettingsChangePassword.html b/plugins/change-password/templates/SettingsChangePassword.html index 646c6ef56..7cd1dc36e 100644 --- a/plugins/change-password/templates/SettingsChangePassword.html +++ b/plugins/change-password/templates/SettingsChangePassword.html @@ -13,9 +13,11 @@
- +
+