/
Coderdev
/
web-static-labs
Обзор
Документация
Войти
/
Coderdev
/
web-static-labs
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
html/lab4/task7/script.js
98 строк
2 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"); criteriaList.innerHTML = ""; 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); // 1. Длина менее 5 if (length < 5) { matched.push("1"); score = 0; renderResult(matched, score); return; } // 2. Длина 5-9 if (length >= 5 && length <= 9) { score += 1; matched.push("2"); } // 3. Длина 10-12 if (length >= 10 && length <= 12) { score += 2; matched.push("3"); } // 4. Длина свыше 12 if (length > 12) { score += 3; matched.push("4"); } // 5. Символы (цифры, буквы, иные символы) let criterion5 = 0; if (typesCount >= 2) criterion5 = 1; if (typesCount === 3) criterion5 = 2; if (criterion5 > 0) { score += criterion5; matched.push(`5 (${criterion5})`); } // 6. Регистр букв if (hasLower && hasUpper) { score += 1; matched.push("6"); } // 7. Иные символы более 30% длины if (length > 0 && specialCount / length > 0.3) { score += 2; matched.push("7"); } // 8. Все буквенные или цифровые сочетания подряд длиной < 3 if (hasShortSequence(password)) { score += 2; matched.push("8"); } if (score > 10) score = 10; renderResult(matched, score); function renderResult(criteria, total) { criteriaList.innerHTML = ""; criteria.forEach(item => { const li = document.createElement("li"); li.textContent = item; criteriaList.appendChild(li); }); scoreElement.textContent = total; } } function hasShortSequence(password) { const groups = password.match(/[A-Za-zА-Яа-яЁё0-9]+/g); if (!groups) return false; return groups.every(group => group.length < 3); }