-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPasswordStrength.html
104 lines (96 loc) · 3.13 KB
/
PasswordStrength.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Strength Checker</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f0f4f7;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background-color: #fff;
padding: 30px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
text-align: center;
width: 300px;
}
h2 {
margin-bottom: 20px;
color: #333;
}
label {
font-weight: bold;
color: #555;
}
input[type="password"] {
width: 100%;
padding: 10px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
#passwordStrength {
font-weight: bold;
margin-top: 10px;
padding: 10px;
border-radius: 5px;
}
.weak {
color: #f44336;
}
.moderate {
color: #ff9800;
}
.strong {
color: #4caf50;
}
</style>
</head>
<body>
<div class="container">
<h2>Password Strength Checker</h2>
<label for="password">Enter Password: </label>
<input type="password" id="passwordInput" onkeyup="checkPasswordStrength()">
<p id="passwordStrength">Password Strength: </p>
</div>
<script>
function checkPasswordStrength() {
const criteria = [
{ regex: /.{8,}/, label: "Minimum 8 characters" }, // Length criterion
{ regex: /[a-z]/, label: "Lowercase letter" }, // Lowercase letters
{ regex: /[A-Z]/, label: "Uppercase letter" }, // Uppercase letters
{ regex: /[0-9]/, label: "Number" }, // Numbers
{ regex: /[$@#&!]/, label: "Special character" } // Special characters
];
const passwordInput = document.getElementById("passwordInput").value;
const passwordStrength = document.getElementById("passwordStrength");
let strength = 0;
// Check each criterion
criteria.forEach(criterion => {
if (criterion.regex.test(passwordInput)) {
strength++;
}
});
// Update strength message and color
const strengthMessages = ["Very Weak", "Weak", "Moderate", "Strong", "Very Strong", "Excellent"];
passwordStrength.innerText = `Password Strength: ${strengthMessages[strength] || "Unknown"}`;
if (strength <= 1) {
passwordStrength.className = "weak";
} else if (strength <= 3) {
passwordStrength.className = "moderate";
} else {
passwordStrength.className = "strong";
}
}
</script>
</body>
</html>