Hello, guys hope you all are well. Today, we are going to learn Password Strength Checker In HTML, CSS & JavaScript.
Password Strength Checker is the simple program that can tests our password and shows how strong our password is.
Let's have a look There are three input fields with some characters, numbers and symbols. As you can see the first field shows our password is weak because i have used only alphabet letters, the second field shows the entered password is medium because I have added some numbers with alphabet letters and the last input field shows that our password is strong because I have entered alphabets, numbers, and special characters.
As we know, to create a strong password we need to combine alphabets (it can be capital letters and small letters), with some numbers (like 1,2,3....9), and some special characters (like @,! $,%,#,&,*). And our password length should be at least 6 or 8 characters minimum length.
Our Password Strength Checker program follows all the above rules.
Password Strength Checker In HTML, CSS & JavaScript | Video
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Strength Checker | Grapdroad</title>
<!-- custom CSS -->
<link rel="stylesheet" href="style.css">
<!-- Fontawesome CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div class="wrapper">
<h1> Password Strength Checker In HTML CSS & JavaScript</h1>
<div class="input_box">
<i class="fa-solid fa-eye-slash show_hide"></i>
<input type="password" placeholder="Enter Password">
</div>
<div class="indicator">
<div class="icon_text">
<i class="fa-solid fa-circle error_icon"></i>
<h5 class="text"> </h5>
</div>
</div>
</div>
<!-- custom JavaScript -->
<script src="main.js"></script>
</body>
</html>
:root
{
--body-color:#2a83e8;
--border-color:#d3d3d3;
--eye-icon-color:#a6a6a6;
--weak-pass-color:#ff6333;
--medium-pass-color:#cc8500;
--strong-pass-color:#22c32a;
}
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
body{
display: flex;
min-height: 100vh;
background-color: var(--body-color);
justify-content: center;
align-items: center;
}
.wrapper{
position: relative;
max-width: 30em;
width: 100%;
background-color: #fff;
border-radius: .5em;
padding: 2em;
box-shadow: -3px -3px 10px #00000040,
3px 3px 15px #00000040;
}
.wrapper h1{
font-size: 1.5em;
font-weight: 800;
letter-spacing: .12em;
margin-bottom: 1em;
text-align: center;
color: #2a83e8;
}
.input_box .show_hide{
position: absolute;
right: 1.5em;
top: 50%;
transform: translateY(-50%);
color: var(--eye-icon-color);
cursor: pointer;
padding: .2em;
}
.input_box input{
width: 100%;
height: 3.3em;
border: .1em solid var(--border-color);
border-radius: .5em;
font-size: 1.2em;
font-weight: 500;
color: #333;
outline: none;
padding: 0 50px 0 16px;
}
.wrapper .input_box{
position: relative;
}
.indicator .icon_text{
display: flex;
align-items: center;
}
.icon_text .error_icon{
margin-right: .5em;
}
.icon_text .text{
font-size: 1em;
font-weight: 500;
letter-spacing: .1em;
}
.wrapper .indicator{
display: none;
}
.wrapper .indicator.active{
display: block;
margin-top: 1em;
}
const input = document.querySelector("input"),
show_hide = document.querySelector(".show_hide"),
indicator = document.querySelector(".indicator"),
icon_text = document.querySelector(".icon_text"),
text = document.querySelector(".text");
show_hide.addEventListener("click",() =>{
if(input.type == "password")
{
input.type = "text";
show_hide.classList.replace("fa-eye-slash" ,"fa-eye");
}
else
{
input.type = "password";
show_hide.classList.replace("fa-eye" ,"fa-eye-slash");
}
});
let alpha = /[a-zA-Z]/,
number = /[0-9]/,
specialchars = /[!,@,#,$,%,^,&,*(,),_,-,+,=,>,<,?,/,~]/;
input.addEventListener("keyup", ()=>{
indicator.classList.add("active");
let val = input.value;
if (val.match(alpha) || val.match(number) || val.match(specialchars))
{
text.textContent = "Password is weak";
icon_text.style.color = " #ff6333";
show_hide.style.color = " #ff6333";
input.style.borderColor = "#ff6333";
}
if (val.match(alpha) && val.match(number) && val.length > 6)
{
text.textContent = "Password is medium";
icon_text.style.color = " #cc8500";
show_hide.style.color = " #cc8500";
input.style.borderColor = "#cc8500";
}
if (val.match(alpha) && val.match(number) && val.match(specialchars) && val.length > 6)
{
text.textContent = "Password is strong";
icon_text.style.color = " #22c32a";
show_hide.style.color = " #22c32a";
input.style.borderColor = "#22c32a";
}
if (val == "") {
indicator.classList.remove("active");
icon_text.style.color = " #a6a6a6";
show_hide.style.color = " #a6a6a6";
input.style.borderColor = "#a6a6a6";
show_hide.classList.replace("fa-eye" ,"fa-eye-slash");
}
});

