/
maxxon
/
web-static-labs
Обзор
Документация
Войти
/
maxxon
/
web-static-labs
Код
Запросы
0
Задачи
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
html/lab4/task7/script.js
79 строк
3 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"); // Clear previous results scoreElement.textContent = ""; criteriaList.innerHTML = ""; // Password Evaluation Logic let score = 0; const matchedCriteria = []; // 1. Length less than 5 if (password.length < 5) { scoreElement.textContent = "0"; criteriaList.innerHTML = "<li>1. Длина менее 5</li>"; 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"); } // Display the results scoreElement.textContent = Math.min(score, 10); matchedCriteria.forEach(criterion => { const li = document.createElement("li"); li.textContent = criterion; criteriaList.appendChild(li); }); }