Skip to content

Commit eb74a90

Browse files
author
Your Name
committed
fix: resolve password-forge-validation
1 parent 02131ee commit eb74a90

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

web-app/js/projects/password-forge.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function getPasswordForgeHTML() {
4444
margin-top: 1rem;
4545
font-size: 1rem;
4646
background-color: var(--bg-color);
47-
color: #000;
47+
color: var(--text-color);
4848
}
4949
5050
.btn-check {
@@ -101,19 +101,32 @@ function initPasswordForge() {
101101
}
102102
});
103103

104-
checkBtn.addEventListener('click', () => {
105-
const password = document.getElementById('passwordInput').value;
106-
const result = document.getElementById('passwordResult');
104+
const rulesContainer = document.getElementById('rulesContainer');
105+
const result = document.getElementById('passwordResult');
107106

107+
function checkRules() {
108+
const password = passwordInput.value;
108109
const hasLength = password.length >= 8;
109110
const hasNumber = /\d/.test(password);
110111
const hasUpper = /[A-Z]/.test(password);
111-
const hasSpecial = /[!@#$%^&*]/.test(password);
112+
const hasSpecial = /[!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~`]/.test(password);
113+
114+
rulesContainer.innerHTML = `
115+
<p>${hasLength ? '✅' : '❌'} Must contain at least 8 characters</p>
116+
<p>${hasNumber ? '✅' : '❌'} Must contain a number</p>
117+
<p>${hasUpper ? '✅' : '❌'} Must contain an uppercase letter</p>
118+
<p>${hasSpecial ? '✅' : '❌'} Must contain a special character</p>
119+
`;
112120

113121
if (hasLength && hasNumber && hasUpper && hasSpecial) {
114122
result.textContent = "✅ Strong Password!";
123+
result.style.color = "var(--success-color)";
115124
} else {
116125
result.textContent = "❌ Password does not meet all rules!";
126+
result.style.color = "var(--danger-color)";
117127
}
118-
});
128+
}
129+
130+
passwordInput.addEventListener('input', checkRules);
131+
checkBtn.addEventListener('click', checkRules);
119132
}

0 commit comments

Comments
 (0)