-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
206 lines (184 loc) · 6.73 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<!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" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inconsolata:wght@600&family=Inter:wght@400;600&display=swap"
rel="stylesheet"
/>
<link rel="stylesheet" href="reset.css" />
<link rel="stylesheet" href="style.css" />
<title>Document</title>
</head>
<body>
<main>
<section class="hero">
<h1 class="title">Gerador de senha</h1>
<p class="subtitle">
Utilize o nosso gerador online para criar uma senha forte e segura.
</p>
</section>
<section class="box">
<div class="password">
<div class="text">
<input type="text" name="password" id="password" />
</div>
<div class="actions">
<button id="copy-1">
<img src="copy.svg" width="42" />
</button>
<button id="renew">
<img src="renew.svg" width="42" />
</button>
</div>
</div>
<div class="security-indicator">
<div id="security-indicator-bar" class="bar"></div>
</div>
</section>
<section class="box customize">
<h3 class="title">Personalizar</h3>
<div class="actions">
<div class="password-length">
<p>Tamanho: <span id="password-length-text">16</span></p>
<input
type="range"
name="password-length"
id="password-length"
class="slider"
value="16"
min="4"
max="64"
/>
</div>
<div class="config">
<label class="checkbox-container">
<span class="text">Maiúsculas</span>
<input type="checkbox" id="uppercase-check" checked />
<span class="checkmark"></span>
</label>
<label class="checkbox-container">
<span class="text">Números</span>
<input type="checkbox" id="number-check" checked />
<span class="checkmark"></span>
</label>
<label class="checkbox-container">
<span class="text">Símbolos</span>
<input type="checkbox" id="symbol-check" checked />
<span class="checkmark"></span>
</label>
</div>
</div>
</section>
<div class="submit">
<button id="copy-2">Copiar senha</button>
</div>
</main>
<script>
const inputEl = document.querySelector("#password")
const upperCaseCheckEl = document.querySelector("#uppercase-check")
const numberCheckEl = document.querySelector("#number-check")
const symbolCheckEl = document.querySelector("#symbol-check")
const securityIndicatorBarEl = document.querySelector(
"#security-indicator-bar"
)
let passwordLength = 16
function generatePassword() {
let chars = "abcdefghjkmnpqrstuvwxyz"
const upperCaseChars = "ABCDEFGHJKLMNPQRSTUVWXYZ"
const numberChars = "123456789"
const symbolChars = "?!@&*()[]"
if (upperCaseCheckEl.checked) {
chars += upperCaseChars
}
if (numberCheckEl.checked) {
chars += numberChars
}
if (symbolCheckEl.checked) {
chars += symbolChars
}
let password = ""
for (let i = 0; i < passwordLength; i++) {
const randomNumber = Math.floor(Math.random() * chars.length)
password += chars.substring(randomNumber, randomNumber + 1)
}
inputEl.value = password
calculateQuality()
calculateFontSize()
}
function calculateQuality() {
// T*0.25 + M*0.15 + N*0.25 + S*0.35 = 100
const percent = Math.round(
(passwordLength / 64) * 25 +
(upperCaseCheckEl.checked ? 15 : 0) +
(numberCheckEl.checked ? 25 : 0) +
(symbolCheckEl.checked ? 35 : 0)
)
securityIndicatorBarEl.style.width = `${percent}%`
if (percent > 69) {
// safe
securityIndicatorBarEl.classList.remove("critical")
securityIndicatorBarEl.classList.remove("warning")
securityIndicatorBarEl.classList.add("safe")
} else if (percent > 50) {
// warning
securityIndicatorBarEl.classList.remove("critical")
securityIndicatorBarEl.classList.add("warning")
securityIndicatorBarEl.classList.remove("safe")
} else {
// critical
securityIndicatorBarEl.classList.add("critical")
securityIndicatorBarEl.classList.remove("warning")
securityIndicatorBarEl.classList.remove("safe")
}
if (percent >= 100) {
securityIndicatorBarEl.classList.add("completed")
} else {
securityIndicatorBarEl.classList.remove("completed")
}
}
function calculateFontSize() {
if (passwordLength > 45) {
inputEl.classList.remove("font-sm")
inputEl.classList.remove("font-xs")
inputEl.classList.add("font-xxs")
} else if (passwordLength > 32) {
inputEl.classList.remove("font-sm")
inputEl.classList.add("font-xs")
inputEl.classList.remove("font-xxs")
} else if (passwordLength > 22) {
inputEl.classList.add("font-sm")
inputEl.classList.remove("font-xs")
inputEl.classList.remove("font-xxs")
} else {
inputEl.classList.remove("font-sm")
inputEl.classList.remove("font-xs")
inputEl.classList.remove("font-xxs")
}
}
function copy() {
navigator.clipboard.writeText(inputEl.value)
}
const passwordLengthEl = document.querySelector("#password-length")
passwordLengthEl.addEventListener("input", function () {
passwordLength = passwordLengthEl.value
document.querySelector("#password-length-text").innerText =
passwordLength
generatePassword()
})
upperCaseCheckEl.addEventListener("click", generatePassword)
numberCheckEl.addEventListener("click", generatePassword)
symbolCheckEl.addEventListener("click", generatePassword)
document.querySelector("#copy-1").addEventListener("click", copy)
document.querySelector("#copy-2").addEventListener("click", copy)
document
.querySelector("#renew")
.addEventListener("click", generatePassword)
generatePassword()
</script>
</body>
</html>