-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
175 lines (155 loc) · 6.99 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
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<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>Gerador de Senha</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" disabled/>
</div>
<div class="actions">
<button id="copy-1">
<img src="copy.svg" alt="Copy" width="42">
</button>
<button id="renew">
<img src="renew.svg" alt="renew" width="42">
</button>
</div>
</div>
<div class="security-indicator">
<div id="security-indicator-bar" class="bar safe" ></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 class="slider" type="range" name="password-lenght" id="password-lenght" 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>
let passwordLength = 16
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")
function generatePassword(){
let chars="abcdefghjkmnopqrstuvwxyz"
const upperCaseChars = "ABCDEFGHJKLMNOPQRSTUVWXYZ"
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(){
const percent = Math.round((passwordLength / 64)* 35 +
(upperCaseCheckEl.checked ? 15 : 0)+
(numberCheckEl.checked ? 25 : 0)+
(symbolCheckEl.checked ? 25 : 0)
)
securityIndicatorBarEl.style.width = `${percent}%`
if(percent > 69){
securityIndicatorBarEl.classList.remove('critical')
securityIndicatorBarEl.classList.remove('warning')
securityIndicatorBarEl.classList.add('safe')
} else if (percent > 50){
securityIndicatorBarEl.classList.remove('critical')
securityIndicatorBarEl.classList.add('warning')
securityIndicatorBarEl.classList.remove('safe')
}else {
securityIndicatorBarEl.classList.add('critical')
securityIndicatorBarEl.classList.remove('warning')
securityIndicatorBarEl.classList.remove('safe')
}
}
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-lenght")
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>