-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword-generator.html
More file actions
171 lines (161 loc) · 4.92 KB
/
Copy pathpassword-generator.html
File metadata and controls
171 lines (161 loc) · 4.92 KB
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>password-generator</title>
<style>
*{
margin: 0;
padding: 0;
}
#container{
width: 25vw;
height: 60vh;
border: .5px solid white;
margin: 100px auto ;
padding-top: 15px;
padding-left: 60px;
padding-right: 60px;
color: white;
border-radius: 10px;
box-shadow: 10px 10px 5px rgba(0,0,0,0.5);
}
#input{
width: 300px;
height: 20px;
margin-top: 15px;
}
#range{
margin-top: 15px;
width: 302px;
accent-color: blue;
}
body{
max-width: 100vw;
max-height: 100vh;
background: linear-gradient(to right bottom,#cf1919,#1956cf);
}
#length{
display: flex;
gap: 160px;
font-size: larger;
margin-top: 10px;
}
#lowercase{
display: flex;
/* flex-basis: 100%; */
/* gap: 114px; */
font-size: larger;
margin-top: 10px;
}
#lowercase span{
flex-basis: 100%;
}
#uppercase span{
flex-basis: 100%;
}
#Number span{
flex-basis: 100%;
}
#punctuation span{
flex-basis: 100%;
}
#uppercase{
display: flex;
/* gap: 105px; */
font-size: larger;
margin-top: 10px;
}
#lowercase input,#uppercase input,#Number input,#punctuation input{
width: 18px;
height: 18px;
accent-color: blue;
}
#Number{
display: flex;
/* gap: 164px; */
font-size: larger;
margin-top: 10px;
}
#punctuation{
display: flex;
/* gap: 135px; */
font-size: larger;
margin-top: 10px;
}
#button{
width: 180px;
height: 25px;
margin-top: 15px;
margin-left: 60px;
}
</style>
</head>
<body>
<div id="container">
<h1>Password-Generator</h1>
<div id="box">
<input type="text" id="input">
</div>
<input type="range" id="range" min="1" max="30" value="8">
<div id="length">
<span>password-length</span>
<span id="pl">8</span>
</div>
<div id="lowercase">
<span>Include lowercase(a-z)</span>
<input type="checkbox" name="" id="lower">
</div>
<div id="uppercase">
<span>Include uppercase(A-Z)</span>
<input type="checkbox" name="" id="upper" checked>
</div>
<div id="Number">
<span>Include Number</span>
<input type="checkbox" name="" id="Num">
</div>
<div id="punctuation">
<span>Include Punctuation</span>
<input type="checkbox" name="" id="punc">
</div>
<button id="button">Generate Password</button>
</div>
<script>
let range=document.getElementById("range");
let lower=document.getElementById("lower");
let upper=document.getElementById("upper");
let punc=document.getElementById("punc");
let Num=document.getElementById("Num");
let button=document.getElementById("button")
let input=document.getElementById("input")
let rangevalue=document.getElementById("pl");
// rangevalue.innerText=range.value;
range.addEventListener("input",()=>{
rangevalue.textContent=range.value;
console.log(range.value)
})
button.addEventListener('click',()=>{
input.value=result();
})
function result(){
const length = range.value;
const charsetLower = "abcdefghijklmnopqrstuvwxyz";
const charsetUpper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const charsetNum = "0123456789";
const charsetPunc = "!@#$%^&*()_+~`|}{[]:;?><,./-=";
let charset = "";
if (lower.checked) charset += charsetLower;
if (upper.checked) charset += charsetUpper;
if (Num.checked) charset += charsetNum;
if (punc.checked) charset += charsetPunc;
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
</script>
</body>
</html>