25 lines
941 B
JavaScript
25 lines
941 B
JavaScript
const passwordInput = document.getElementById("regPassword");
|
|
const strengthBar = document.getElementById("passwordStrengthBar");
|
|
|
|
passwordInput.addEventListener("input", () => {
|
|
const password = passwordInput.value;
|
|
const strength = getPasswordStrength(password);
|
|
updateStrengthBar(strength);
|
|
});
|
|
|
|
function getPasswordStrength(password) {
|
|
let strength = 0;
|
|
if (password.length >= 8) strength++; // Mindestlänge
|
|
if (/[A-Z]/.test(password)) strength++; // Großbuchstaben
|
|
if (/[a-z]/.test(password)) strength++; // Kleinbuchstaben
|
|
if (/[0-9]/.test(password)) strength++; // Zahlen
|
|
if (/[^A-Za-z0-9]/.test(password)) strength++; // Sonderzeichen
|
|
return strength;
|
|
}
|
|
|
|
function updateStrengthBar(strength) {
|
|
const colors = ["#ccc", "red", "orange", "yellow", "lightgreen", "green"];
|
|
strengthBar.style.width = `${(strength / 5) * 100}%`;
|
|
strengthBar.style.backgroundColor = colors[strength];
|
|
}
|