mirror of
https://github.com/andwati/zitadel.git
synced 2026-11-17 10:55:12 +00:00
feat: check passwordpolicy on login (#477)
* fix: password complexity policy * feat: check password policy * feat: check password policy * fix: password policy on password change * fix: remove double policy check * feat: check pw policy on register * feat: check pw policy on init * fix: hover on secondary buttons * fix: use data set instead of hidden inputs * fix: disabled button * fix: en login * fix: read policy * feat: check if org exists * multiple checks * feat: validate all forms * fix: check all forms * fix: remove unused err Co-authored-by: Livio Amstutz <[email protected]>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
function CheckChangePwPolicy() {
|
||||
let policyElement = document.getElementById("change-new-password")
|
||||
let pwNew = policyElement.value;
|
||||
let pwNewConfirmation = document.getElementById("change-password-confirmation").value;
|
||||
|
||||
if (ComplexityPolicyCheck(policyElement, pwNew) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pwNew == pwNewConfirmation;
|
||||
}
|
||||
|
||||
let button = document.getElementById("change-password--button");
|
||||
disableSubmit(CheckChangePwPolicy, button);
|
||||
@@ -0,0 +1,3 @@
|
||||
|
||||
let button = document.getElementById("submit-button");
|
||||
disableSubmit(undefined, button);
|
||||
@@ -0,0 +1,29 @@
|
||||
function disableSubmit(checks, button) {
|
||||
console.log("GUGUS");
|
||||
let form = document.getElementsByTagName('form')[0];
|
||||
let inputs = form.getElementsByTagName('input');
|
||||
for (i = 0; i < inputs.length; i++) {
|
||||
inputs[i].addEventListener('input', function () {
|
||||
if (checks != undefined) {
|
||||
if (checks() === false) {
|
||||
button.disabled = true;
|
||||
return
|
||||
}
|
||||
}
|
||||
if (checkRequired(form, inputs) === false) {
|
||||
button.disabled = true;
|
||||
return
|
||||
}
|
||||
button.disabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function checkRequired(form, inputs) {
|
||||
for (i = 0; i < inputs.length; i++) {
|
||||
if (inputs[i].required && inputs[i].value == '') {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
function CheckInitPwPolicy() {
|
||||
let policyElement = document.getElementById("password");
|
||||
let pwNew = policyElement.value;
|
||||
let pwNewConfirmation = document.getElementById("passwordconfirm").value;
|
||||
|
||||
if (ComplexityPolicyCheck(policyElement, pwNew) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pwNew == pwNewConfirmation;
|
||||
}
|
||||
|
||||
let button = document.getElementById("init-button");
|
||||
disableSubmit(CheckInitPwPolicy, button);
|
||||
@@ -0,0 +1,68 @@
|
||||
function ComplexityPolicyCheck(policyElement, pwNew) {
|
||||
let minLength = policyElement.dataset.minlength;
|
||||
let upperRegex = policyElement.dataset.hasUppercase;
|
||||
let lowerRegex = policyElement.dataset.hasLowercase;
|
||||
let numberRegex = policyElement.dataset.hasNumber;
|
||||
let symbolRegex = policyElement.dataset.hasSymbol;
|
||||
|
||||
let valid = true;
|
||||
|
||||
let minlengthelem = document.getElementById('minlength')
|
||||
if (pwNew.length >= minLength) {
|
||||
ValidPolicy(minlengthelem);
|
||||
valid = true;
|
||||
} else {
|
||||
InvalidPolicy(minlengthelem);
|
||||
valid = false;
|
||||
}
|
||||
let upper = document.getElementById('uppercase')
|
||||
if (upperRegex !== "") {
|
||||
if (RegExp(upperRegex).test(pwNew)) {
|
||||
ValidPolicy(upper);
|
||||
valid = true;
|
||||
} else {
|
||||
InvalidPolicy(upper);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
let lower = document.getElementById('lowercase')
|
||||
if (lowerRegex !== "") {
|
||||
if (RegExp(lowerRegex).test(pwNew)) {
|
||||
ValidPolicy(lower);
|
||||
valid = true;
|
||||
} else {
|
||||
InvalidPolicy(lower);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
let number = document.getElementById('number')
|
||||
if (numberRegex != "") {
|
||||
if (RegExp(numberRegex).test(pwNew)) {
|
||||
ValidPolicy(number);
|
||||
valid = true;
|
||||
} else {
|
||||
InvalidPolicy(number);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
let symbol = document.getElementById('symbol')
|
||||
if (symbolRegex != "") {
|
||||
if (RegExp(symbolRegex).test(pwNew)) {
|
||||
ValidPolicy(symbol)
|
||||
valid = true;
|
||||
} else {
|
||||
InvalidPolicy(symbol);
|
||||
valid = false;
|
||||
}
|
||||
}
|
||||
return valid;
|
||||
}
|
||||
function ValidPolicy(element) {
|
||||
element.classList.remove('invalid')
|
||||
element.getElementsByTagName('i')[0].innerText = 'check';
|
||||
}
|
||||
|
||||
function InvalidPolicy(element) {
|
||||
element.classList.add('invalid')
|
||||
element.getElementsByTagName('i')[0].innerText = 'clear';
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
function CheckRegisterPwPolicy() {
|
||||
let policyElement = document.getElementById("register-password");
|
||||
let pwNew = policyElement.value;
|
||||
let pwNewConfirmation = document.getElementById("register-password-confirmation").value;
|
||||
|
||||
if (ComplexityPolicyCheck(policyElement, pwNew) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return pwNew == pwNewConfirmation;
|
||||
}
|
||||
|
||||
let button = document.getElementById("register-button");
|
||||
disableSubmit(CheckRegisterPwPolicy, button);
|
||||
Reference in New Issue
Block a user