From 03a77b381e783eddfaf956ef8e4b6ccbdffd4834 Mon Sep 17 00:00:00 2001 From: Livio Spring Date: Thu, 9 Jun 2022 15:48:57 +0200 Subject: [PATCH] fix: password check policy correctly (#3787) * fix: password check policy correctly * fix: password check policy correctly --- .../scripts/change_password_check.js | 4 +-- .../scripts/password_policy_check.js | 26 +++++++------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/internal/api/ui/login/static/resources/scripts/change_password_check.js b/internal/api/ui/login/static/resources/scripts/change_password_check.js index 49a8fa7f1..cd5b3deea 100644 --- a/internal/api/ui/login/static/resources/scripts/change_password_check.js +++ b/internal/api/ui/login/static/resources/scripts/change_password_check.js @@ -10,8 +10,8 @@ function CheckChangePwPolicy() { policyElement.setAttribute("color", "primary"); } - return pwNew == pwNewConfirmation; + return pwNew === pwNewConfirmation; } let button = document.getElementById("change-password-button"); -disableSubmit(CheckChangePwPolicy, button); \ No newline at end of file +disableSubmit(CheckChangePwPolicy, button); diff --git a/internal/api/ui/login/static/resources/scripts/password_policy_check.js b/internal/api/ui/login/static/resources/scripts/password_policy_check.js index d36e5cac1..d0bd8d9f3 100644 --- a/internal/api/ui/login/static/resources/scripts/password_policy_check.js +++ b/internal/api/ui/login/static/resources/scripts/password_policy_check.js @@ -5,65 +5,59 @@ function ComplexityPolicyCheck(policyElement, pwNew, pwNewConfirmation) { let numberRegex = policyElement.dataset.hasNumber; let symbolRegex = policyElement.dataset.hasSymbol; - let valid = true; + let invalid = 0; let minlengthelem = document.getElementById('minlength'); if (pwNew.length >= minLength) { ValidPolicy(minlengthelem); - valid = true; } else { InvalidPolicy(minlengthelem); - valid = false; + invalid++; } let upper = document.getElementById('uppercase'); if (upperRegex !== "") { if (RegExp(upperRegex).test(pwNew)) { ValidPolicy(upper); - valid = true; } else { InvalidPolicy(upper); - valid = false; + invalid++; } } let lower = document.getElementById('lowercase'); if (lowerRegex !== "") { if (RegExp(lowerRegex).test(pwNew)) { ValidPolicy(lower); - valid = true; } else { InvalidPolicy(lower); - valid = false; + invalid++; } } let number = document.getElementById('number'); - if (numberRegex != "") { + if (numberRegex !== "") { if (RegExp(numberRegex).test(pwNew)) { ValidPolicy(number); - valid = true; } else { InvalidPolicy(number); - valid = false; + invalid++; } } let symbol = document.getElementById('symbol'); - if (symbolRegex != "") { + if (symbolRegex !== "") { if (RegExp(symbolRegex).test(pwNew)) { ValidPolicy(symbol); - valid = true; } else { InvalidPolicy(symbol); - valid = false; + invalid++; } } let confirmation = document.getElementById('confirmation'); if (pwNew === pwNewConfirmation && pwNewConfirmation !== "" ) { ValidPolicy(confirmation); - valid = true; } else { InvalidPolicy(confirmation); - valid = false; + invalid++; } - return valid; + return invalid===0; } function ValidPolicy(element) {