/
Coderdev
/
web-static-labs
Обзор
Документация
Войти
/
Coderdev
/
web-static-labs
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
html/lab4/task8/script.js
109 строк
3 KB
Coderdev
1
17 мар 2026, 12:12
17 мар 2026, 12:12
b82e571
Код
Авторство
О чём код?
function checkPassword() { const password = document.getElementById("passwordInput").value; const criteriaList = document.getElementById("criteriaList"); const scoreElement = document.getElementById("score"); const segments = document.querySelectorAll(".segment"); criteriaList.innerHTML = ""; segments.forEach(seg => seg.style.background = "#d1d5db"); let score = 0; let matched = []; const length = password.length; const hasDigits = /\d/.test(password); const hasLower = /[a-zа-яё]/.test(password); const hasUpper = /[A-ZА-ЯЁ]/.test(password); const specialMatches = password.match(/[~!#$%^&*()_\-+=?\/.\[\]{}<>|\\]/g) || []; const specialCount = specialMatches.length; const typesCount = (hasDigits ? 1 : 0) + (hasLower || hasUpper ? 1 : 0) + (specialCount > 0 ? 1 : 0); if (length < 5) { matched.push("1"); score = 0; render(criteriaList, scoreElement, matched, score); paintIndicator(score, length, segments); return; } if (length >= 5 && length <= 9) { score += 1; matched.push("2"); } if (length >= 10 && length <= 12) { score += 2; matched.push("3"); } if (length > 12) { score += 3; matched.push("4"); } let criterion5 = 0; if (typesCount >= 2) criterion5 = 1; if (typesCount === 3) criterion5 = 2; if (criterion5 > 0) { score += criterion5; matched.push(`5 (${criterion5})`); } if (hasLower && hasUpper) { score += 1; matched.push("6"); } if (length > 0 && specialCount / length > 0.3) { score += 2; matched.push("7"); } if (hasShortSequence(password)) { score += 2; matched.push("8"); } if (score > 10) score = 10; render(criteriaList, scoreElement, matched, score); paintIndicator(score, length, segments); } function render(criteriaList, scoreElement, matched, score) { criteriaList.innerHTML = ""; matched.forEach(item => { const li = document.createElement("li"); li.textContent = item; criteriaList.appendChild(li); }); scoreElement.textContent = score; } function paintIndicator(score, length, segments) { if (length === 0) return; let color = ""; if (score >= 0 && score <= 3) color = "red"; else if (score >= 4 && score <= 7) color = "gold"; else color = "green"; const count = Math.min(score, 10); for (let i = 0; i < count; i++) { segments[i].style.background = color; } } function hasShortSequence(password) { const groups = password.match(/[A-Za-zА-Яа-яЁё0-9]+/g); if (!groups) return false; return groups.every(group => group.length < 3); }