-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
133 lines (119 loc) · 4.85 KB
/
index.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Validation</title>
<link rel="icon" value="png" href="https://cdn-icons-png.freepik.com/512/421/421648.png">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<!-- Font Awsome -->
<link href="//netdna.bootstrapcdn.com/twitter-bootstrap/2.3.2/css/bootstrap-combined.no-icons.min.css" rel="stylesheet">
<link href="//netdna.bootstrapcdn.com/font-awesome/3.2.1/css/font-awesome.css" rel="stylesheet">
<style>
body {
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f0f0f0;
}
.container {
padding: 20px;
background-color: #ffffff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
border-radius: 5px;
max-width: 450px;
text-align: center;
}
.alert {
margin-top: 10px;
padding: 10px;
background-color: #ffffff;
box-shadow: 0px 0px 10px rgba(0, 0, 0, 0.1);
text-align: left;
}
.alerttext {
color: red;
font-size: 15px;
transition: 1s;
}
#password {
outline: none;
border: none;
border-left: .3em solid red;
background: rgba(239, 123, 123, .2);
border-radius: .2em;
padding: .4em;
width: 100%;
}
</style>
</head>
<body>
<div class="container">
<label for="password"><b>Password</b></label>
<input type="text" id="password">
<div class="alert">
<span class="alerttext" id="upper"> At least <strong>one uppercase</strong></span><br>
<span class="alerttext" id="lower"> At least <strong>one lowercase</strong></span><br>
<span class="alerttext" id="number"> At least <strong>one number</strong></span><br>
<span class="alerttext" id="symbol"> At least <strong>one symbol</strong></span><br>
<span class="alerttext" id="size"> Minimum <strong>8 characters</strong></span>
</div>
</div>
<script>
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowercase = "abcdefghijklmnopqrstuvwxyz";
const numbercase = "0123456789";
const symbolcase = "~`!@#$%^&*()_-+={[}]|\\:;'<,>.?/";
const minLength = 8;
document.getElementById("password").addEventListener("input", function () {
const input = document.getElementById("password").value;
let hasUpper = false;
let hasLower = false;
let hasNumber = false;
let hasSymbol = false;
let hassize = false;
for (let i = 0; i < input.length; i++) {
const char = input.charAt(i);
if (uppercase.includes(char)) {
hasUpper = true;
}
if (lowercase.includes(char)) {
hasLower = true;
}
if (numbercase.includes(char)) {
hasNumber = true;
}
if (symbolcase.includes(char)) {
hasSymbol = true;
}
if(input.length>=minLength){
hassize=true;
}
}
// Color of the texts
document.getElementById("upper").style.color = hasUpper ? "green" : "red";
document.getElementById("lower").style.color = hasLower ? "green" : "red";
document.getElementById("number").style.color = hasNumber ? "green" : "red";
document.getElementById("symbol").style.color = hasSymbol ? "green" : "red";
document.getElementById("size").style.color = hassize? "green" : "red";
// style of the input field
if (hasUpper && hasLower && hasNumber && hasSymbol && hassize) {
this.style.borderLeft = ".3em solid green";
this.style.background = "rgb(120, 239, 146)";
this.style.color = "green";
} else {
this.style.borderLeft = ".3em solid red";
this.style.background = "rgba(239, 123, 123, .2)";
this.style.color = "red";
}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"
integrity="sha384-YvpcrYf0tY3lHB60NNkmXc5s9fDVZLESaAA55NDzOxhy9GkcIdslK1eN7N6jIeHz" crossorigin="anonymous">
</script>
</body>
</html>