/
maxxon
/
web-static-labs
Обзор
Документация
Войти
/
maxxon
/
web-static-labs
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
html/lab4/task8/script.js
125 строк
4 KB
maxxon
lab1 lab2 lab3 lab4
12 ноя 2025, 02:32
12 ноя 2025, 02:32
aa1390d
Код
Авторство
О чём код?
function evaluatePassword() { const password = document.getElementById("password").value; const scoreElement = document.getElementById("score"); const criteriaList = document.getElementById("criteria"); const indicator = document.getElementById("indicator"); // Clear previous results scoreElement.textContent = ""; criteriaList.innerHTML = ""; indicator.innerHTML = ""; let score = 0; const matchedCriteria = []; // Array to store the criteria // 1. Length less than 5 if (password.length < 5) { scoreElement.textContent = "0"; matchedCriteria.push("1. Длина менее 5"); updateIndicator(0); criteriaList.innerHTML = matchedCriteria.map(criterion => `<li>${criterion}</li>`).join(''); return; } // 2. Length 5-9 if (password.length >= 5 && password.length <= 9) { score += 1; matchedCriteria.push("2. Длина 5-9"); } // 3. Length 10-12 if (password.length >= 10 && password.length <= 12) { score += 2; matchedCriteria.push("3. Длина 10-12"); } // 4. Length greater than 12 if (password.length > 12) { score += 3; matchedCriteria.push("4. Длина свыше 12"); } // 5. Character types (digits, letters, symbols) let charTypes = 0; if (/[0-9]/.test(password)) charTypes++; if (/[a-z]/.test(password)) charTypes++; if (/[A-Z]/.test(password)) charTypes++; if (/[~!#$%^&*()_+=\-`{}|\[\]:";'<>?,.\/]/.test(password)) charTypes++; score += Math.min(charTypes - 1, 2); // max 2 points if (charTypes > 1) { matchedCriteria.push(`5. Символы (цифры, буквы, иные символы*) (${Math.min(charTypes - 1, 2)})`); } // 6. Case sensitivity if (/[A-Z]/.test(password) && /[a-z]/.test(password)) { score += 1; matchedCriteria.push("6. Регистр букв"); } // 7. Special characters more than 30% (not letters and numbers) const specialChars = password.replace(/[a-zA-Z0-9]/g, ''); if (specialChars.length / password.length > 0.3) { score += 2; matchedCriteria.push("7. Иные символы более 30% длины (не буквы и цифры)"); } // 8. All letter or number sequences length < 3 const sequences = password.match(/[a-zA-Z]+|[0-9]+/g) || []; const hasLongSequence = sequences.some(seq => seq.length >= 3); if (!hasLongSequence) { score += 2; matchedCriteria.push("8. Все буквенные или цифровые сочетания (буквы или цифры подряд) длиной менее 3"); } const finalScore = Math.min(score, 10); // Display the results scoreElement.textContent = finalScore; // Update indicator updateIndicator(finalScore); //Display criteria criteriaList.innerHTML = matchedCriteria.map(criterion => `<li>${criterion}</li>`).join(''); } function updateIndicator(score) { const indicator = document.getElementById("indicator"); indicator.innerHTML = ""; // Очищаем предыдущий индикатор for (let i = 0; i < 10; i++) { const segment = document.createElement("div"); segment.classList.add("indicator-segment"); // Default styles segment.style.width = "10px"; segment.style.height = "5px"; segment.style.marginRight = "1px"; segment.style.border = "1px solid #ccc"; segment.style.backgroundColor = "#ddd"; // Серый по умолчанию if (i < score) { segment.classList.add("active"); // Активируем сегмент // Apply color based on score if (score >= 0 && score <= 3) { segment.style.backgroundColor = "red"; } else if (score >= 4 && score <= 7) { segment.style.backgroundColor = "yellow"; } else if (score >= 8 && score <= 10) { segment.style.backgroundColor = "green"; } } indicator.appendChild(segment); } if (score === 0) { indicator.innerHTML = ""; } } document.getElementById("password").addEventListener("input", function() { if (this.value.length === 0) { document.getElementById("indicator").innerHTML = ""; } });