
И я хочу, чтобы при выполнении требования ставилась галочка.
Он закодирован в HTML, scss и Javascript. Код следующий:
Код: Выделить всё
document.getElementById("password").addEventListener("input", function() {
var password = this.value.trim(); // Trim to remove leading and trailing spaces
var capitalCheck = document.getElementById("capitalCheck").querySelector(".indicator");
var numberCheck = document.getElementById("numberCheck").querySelector(".indicator");
var symbolCheck = document.getElementById("symbolCheck").querySelector(".indicator");
capitalCheck.textContent = /[A-Z]/.test(password) ? '✔' : '✘';
numberCheck.textContent = /\d/.test(password) ? '✔' : '✘';
symbolCheck.textContent = /[!@#$%^&*()_+\-=[\]{};':"\\|,./?]/.test(password) ? '✔' : '✘';
capitalCheck.style.visibility = /[A-Z]/.test(password) ? "visible" : "visible";
numberCheck.style.visibility = /\d/.test(password) ? "visible" : "visible";
symbolCheck.style.visibility = /[!@#$%^&*()_+\-=[\]{};':"\\|,./?]/.test(password) ? "visible" : "visible";
});
function calculateTime() {
var password = document.getElementById("password").value;
var charCount = password.length;
var hasUpperCase = /[A-Z]/.test(password);
var hasNumber = /\d/.test(password);
var hasSymbol = /[!@#$%^&*()_+\-=[\]{};':"\\|,./?]/.test(password);
var possibleCharacters = 26 + (hasUpperCase ? 26 : 0) + (hasNumber ? 10 : 0) + (hasSymbol ? 32 : 0); // lowercase letters + uppercase letters + numbers + symbols
var permutations = Math.pow(possibleCharacters, charCount);
var seconds = permutations / 1000000000; // divide by 1 billion to convert to seconds
var minutes = seconds / 60;
var hours = minutes / 60;
var days = hours / 24;
var years = days / 365;
var result = "It would take approximately ";
if (years >= 1) {
result += Math.floor(years) + " years, " + Math.floor(days % 365) + " days, " + Math.floor(hours % 24) + " hours, " + Math.floor(minutes % 60) + " minutes, and " + Math.floor(seconds % 60) + " seconds to crack this password.";
} else if (days >= 1) {
result += Math.floor(days) + " days, " + Math.floor(hours % 24) + " hours, " + Math.floor(minutes % 60) + " minutes, and " + Math.floor(seconds % 60) + " seconds to crack this password.";
} else if (hours >= 1) {
result += Math.floor(hours) + " hours, " + Math.floor(minutes % 60) + " minutes, and " + Math.floor(seconds % 60) + " seconds to crack this password.";
} else if (minutes >= 1) {
result += Math.floor(minutes) + " minutes, and " + Math.floor(seconds % 60) + " seconds to crack this password.";
} else {
result += Math.ceil(seconds) + " seconds to crack this password.";
}
document.getElementById("result").innerText = result;
}
Код: Выделить всё
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
width: 400px;
padding: 30px;
background-color: #fff;
border-radius: 5px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
h1 {
font-size: 24px;
text-align: center;
margin-bottom: 20px;
}
label {
font-size: 16px;
display: block;
margin-bottom: 10px;
}
input[type="password"] {
width: 100%;
padding: 10px;
margin-bottom: 20px;
border: 1px solid #ccc;
border-radius: 3px;
}
button {
padding: 10px 20px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 3px;
cursor: pointer;
font-size: 16px;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #0056b3;
}
#result {
margin-top: 20px;
font-size: 18px;
text-align: center;
}
.criteria {
display: flex;
justify-content: space-between;
margin-bottom: 20px;
}
.criteria-item {
font-size: 16px;
}
.indicator {
font-size: 16px;
color: red;
visibility: hidden;
}
Код: Выделить всё
Password Strength Checker
Password Strength Checker
Enter Password:
Capital Letters:
Numbers:
Symbols:
Calculate
Заранее спасибо!
Подробнее здесь: https://stackoverflow.com/questions/784 ... -fulfilled