fix: password check policy correctly (#3787)

* fix: password check policy correctly

* fix: password check policy correctly
This commit is contained in:
Livio Spring
2022-06-09 15:48:57 +02:00
committed by GitHub
parent 7f34ce1891
commit 03a77b381e
2 changed files with 12 additions and 18 deletions

View File

@@ -10,8 +10,8 @@ function CheckChangePwPolicy() {
policyElement.setAttribute("color", "primary"); policyElement.setAttribute("color", "primary");
} }
return pwNew == pwNewConfirmation; return pwNew === pwNewConfirmation;
} }
let button = document.getElementById("change-password-button"); let button = document.getElementById("change-password-button");
disableSubmit(CheckChangePwPolicy, button); disableSubmit(CheckChangePwPolicy, button);

View File

@@ -5,65 +5,59 @@ function ComplexityPolicyCheck(policyElement, pwNew, pwNewConfirmation) {
let numberRegex = policyElement.dataset.hasNumber; let numberRegex = policyElement.dataset.hasNumber;
let symbolRegex = policyElement.dataset.hasSymbol; let symbolRegex = policyElement.dataset.hasSymbol;
let valid = true; let invalid = 0;
let minlengthelem = document.getElementById('minlength'); let minlengthelem = document.getElementById('minlength');
if (pwNew.length >= minLength) { if (pwNew.length >= minLength) {
ValidPolicy(minlengthelem); ValidPolicy(minlengthelem);
valid = true;
} else { } else {
InvalidPolicy(minlengthelem); InvalidPolicy(minlengthelem);
valid = false; invalid++;
} }
let upper = document.getElementById('uppercase'); let upper = document.getElementById('uppercase');
if (upperRegex !== "") { if (upperRegex !== "") {
if (RegExp(upperRegex).test(pwNew)) { if (RegExp(upperRegex).test(pwNew)) {
ValidPolicy(upper); ValidPolicy(upper);
valid = true;
} else { } else {
InvalidPolicy(upper); InvalidPolicy(upper);
valid = false; invalid++;
} }
} }
let lower = document.getElementById('lowercase'); let lower = document.getElementById('lowercase');
if (lowerRegex !== "") { if (lowerRegex !== "") {
if (RegExp(lowerRegex).test(pwNew)) { if (RegExp(lowerRegex).test(pwNew)) {
ValidPolicy(lower); ValidPolicy(lower);
valid = true;
} else { } else {
InvalidPolicy(lower); InvalidPolicy(lower);
valid = false; invalid++;
} }
} }
let number = document.getElementById('number'); let number = document.getElementById('number');
if (numberRegex != "") { if (numberRegex !== "") {
if (RegExp(numberRegex).test(pwNew)) { if (RegExp(numberRegex).test(pwNew)) {
ValidPolicy(number); ValidPolicy(number);
valid = true;
} else { } else {
InvalidPolicy(number); InvalidPolicy(number);
valid = false; invalid++;
} }
} }
let symbol = document.getElementById('symbol'); let symbol = document.getElementById('symbol');
if (symbolRegex != "") { if (symbolRegex !== "") {
if (RegExp(symbolRegex).test(pwNew)) { if (RegExp(symbolRegex).test(pwNew)) {
ValidPolicy(symbol); ValidPolicy(symbol);
valid = true;
} else { } else {
InvalidPolicy(symbol); InvalidPolicy(symbol);
valid = false; invalid++;
} }
} }
let confirmation = document.getElementById('confirmation'); let confirmation = document.getElementById('confirmation');
if (pwNew === pwNewConfirmation && pwNewConfirmation !== "" ) { if (pwNew === pwNewConfirmation && pwNewConfirmation !== "" ) {
ValidPolicy(confirmation); ValidPolicy(confirmation);
valid = true;
} else { } else {
InvalidPolicy(confirmation); InvalidPolicy(confirmation);
valid = false; invalid++;
} }
return valid; return invalid===0;
} }
function ValidPolicy(element) { function ValidPolicy(element) {