-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-password.html
More file actions
342 lines (315 loc) · 11.4 KB
/
generate-password.html
File metadata and controls
342 lines (315 loc) · 11.4 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
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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
<!DOCTYPE html>
<html lang="en">
<head>
<!--
asdf
-->
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Password Generator Rev 3.10</title>
<style>
html, body {
height: 100%;
margin: 0;
}
body {
font-family: Arial, sans-serif;
display: flex;
justify-content: center;
align-items: start;
padding: 40px 20px;
background-color: #f0f0f0;
overflow-y: auto;
box-sizing: border-box;
}
.container {
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
text-align: center;
width: 90%;
max-width: 400px;
transition: max-height 0.3s ease;
}
#featureSection {
display: none;
}
input[type="text"] {
width: 100%;
padding: 10px;
margin: 10px 0;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 4px;
}
input[type="range"] {
width: 100%;
}
.options {
text-align: left;
margin: 10px 0;
}
.options label {
display: block;
margin: 5px 0;
}
button {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
background-color: #007BFF;
color: #fff;
border: none;
border-radius: 5px;
margin-top: 10px;
}
button:hover {
background-color: #0056b3;
}
#copyMessage {
font-size: 14px;
color: green;
margin-top: 4px;
display: none;
}
#strengthMeter {
height: 10px;
width: 100%;
background: #eee;
border-radius: 5px;
overflow: hidden;
margin-top: 10px;
}
#strengthBar {
height: 100%;
width: 0%;
background: red;
transition: width 0.3s ease;
}
#strengthText {
font-size: 14px;
margin-top: 6px;
}
#toggleFeatures {
background: none;
border: none;
color: #007BFF;
font-size: 16px;
cursor: pointer;
text-decoration: underline;
margin-top: 20px;
}
#toggleFeatures:hover {
color: #0056b3;
}
#historyList {
margin-top: 20px;
text-align: left;
font-size: 14px;
}
#historyList li {
font-family: monospace;
padding: 2px 0;
}
.copy-icon {
margin-left: 10px;
color: #007BFF;
cursor: pointer;
}
.copy-text {
margin-left: 5px;
color: #007BFF;
cursor: pointer;
text-decoration: underline;
}
.timestamp {
display: block;
font-size: 12px;
color: #666;
}
#clearHistoryBtn {
margin-top: 10px;
background-color: #dc3545;
}
#clearHistoryBtn:hover {
background-color: #a92834;
}
</style>
</head>
<body>
<div class="container">
<h1>Password Generator</h1>
<input type="text" id="password" readonly placeholder="Your Secure Password" aria-live="polite">
<div id="copyMessage">Password copied!</div>
<button onclick="copyPassword()">Copy</button>
<div id="strengthMeter"><div id="strengthBar"></div></div>
<div id="strengthText"></div>
<div class="options">
<label>Password Length: <span id="lengthValue">16</span></label>
<input type="range" id="lengthSlider" min="8" max="256" value="16">
<label><input type="checkbox" id="includeUppercase" checked> Include Uppercase Letters</label>
<label><input type="checkbox" id="includeLowercase" checked> Include Lowercase Letters</label>
<label><input type="checkbox" id="includeNumbers" checked> Include Numbers</label>
<label><input type="checkbox" id="includeSymbols" checked> Include Symbols</label>
<label><input type="checkbox" id="excludeAmbiguous" checked> Exclude Ambiguous /\|IiLl1oO0</label>
<label><input type="checkbox" id="excludeExtraSpecial" checked> Exclude Extra Special ()_`|}{[]:;.,/</label>
</div>
<button id="generateButton">Generate Password</button>
<ul id="historyList"></ul>
<button id="clearHistoryBtn" onclick="clearHistory()">Clear History</button>
<div id="featureWrapper">
<button id="toggleFeatures" onclick="toggleFeatureSection()">▶ Show Features</button>
<div id="featureSection">
<!-- feature content remains unchanged -->
</div>
</div>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const slider = document.getElementById('lengthSlider');
const inputs = document.querySelectorAll('#includeUppercase, #includeLowercase, #includeNumbers, #includeSymbols, #excludeAmbiguous, #excludeExtraSpecial');
slider.addEventListener('input', () => {
updateLengthValue(slider.value);
generatePassword();
});
inputs.forEach(input => input.addEventListener('change', generatePassword));
document.getElementById('generateButton').addEventListener('click', generatePassword);
generatePassword();
});
function updateLengthValue(value) {
document.getElementById('lengthValue').textContent = value;
}
function generatePassword() {
const length = parseInt(document.getElementById('lengthSlider').value);
const includeUppercase = document.getElementById('includeUppercase').checked;
const includeLowercase = document.getElementById('includeLowercase').checked;
const includeNumbers = document.getElementById('includeNumbers').checked;
const includeSymbols = document.getElementById('includeSymbols').checked;
const excludeAmbiguous = document.getElementById('excludeAmbiguous').checked;
const excludeExtraSpecial = document.getElementById('excludeExtraSpecial').checked;
let uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
let lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
let numberChars = '0123456789';
let symbolChars = '!@#$%^&*+~?><-=';
const ambiguousChars = '/\\|IiLl1oO0';
const extraSpecialChars = '()_`}{[]:;.,';
if (excludeAmbiguous) {
uppercaseChars = removeCharacters(uppercaseChars, ambiguousChars);
lowercaseChars = removeCharacters(lowercaseChars, ambiguousChars);
numberChars = removeCharacters(numberChars, ambiguousChars);
}
if (excludeExtraSpecial) {
symbolChars = removeCharacters(symbolChars, extraSpecialChars);
}
let charSet = '';
let guaranteed = [];
if (includeUppercase) { charSet += uppercaseChars; guaranteed.push(randomChar(uppercaseChars)); }
if (includeLowercase) { charSet += lowercaseChars; guaranteed.push(randomChar(lowercaseChars)); }
if (includeNumbers) { charSet += numberChars; guaranteed.push(randomChar(numberChars)); }
if (includeSymbols) { charSet += symbolChars; guaranteed.push(randomChar(symbolChars)); }
if (charSet === '') {
document.getElementById('password').value = '';
return alert('Please select at least one character type.');
}
const cryptoObj = window.crypto || window.msCrypto;
const randomValues = new Uint32Array(length);
cryptoObj.getRandomValues(randomValues);
let password = guaranteed.join('');
for (let i = guaranteed.length; i < length; i++) {
password += charSet.charAt(randomValues[i] % charSet.length);
}
password = shuffleString(password);
document.getElementById('password').value = password;
evaluateStrength(password);
updateHistory(password);
}
function updateHistory(password) {
let history = JSON.parse(localStorage.getItem('passwordHistory') || '[]');
history.unshift({ pw: password, ts: new Date().toLocaleString() });
history = history.slice(0, 10);
localStorage.setItem('passwordHistory', JSON.stringify(history));
const list = document.getElementById('historyList');
list.innerHTML = '<strong>Last 10 Passwords:</strong>' +
history.map(h => `<li>${h.pw} <span class="timestamp">${h.ts}</span> <span class="copy-icon" onclick="copyText('${h.pw}')">📋</span><span class="copy-text" onclick="copyText('${h.pw}')">copy</span></li>`).join('');
}
function copyText(text) {
navigator.clipboard.writeText(text).then(() => {
const msg = document.getElementById('copyMessage');
msg.style.display = 'block';
setTimeout(() => msg.style.display = 'none', 2000);
});
}
function clearHistory() {
localStorage.removeItem('passwordHistory');
document.getElementById('historyList').innerHTML = '';
}
function removeCharacters(charSet, charsToRemove) {
return [...charSet].filter(c => !charsToRemove.includes(c)).join('');
}
function randomChar(charSet) {
return charSet.charAt(Math.floor(Math.random() * charSet.length));
}
function shuffleString(str) {
return [...str].sort(() => Math.random() - 0.5).join('');
}
function copyPassword() {
const passField = document.getElementById('password');
const copyMessage = document.getElementById('copyMessage');
navigator.clipboard.writeText(passField.value)
.then(() => {
copyMessage.style.display = 'block';
setTimeout(() => copyMessage.style.display = 'none', 2000);
})
.catch(() => {
copyMessage.textContent = 'Failed to copy!';
copyMessage.style.color = 'red';
copyMessage.style.display = 'block';
setTimeout(() => {
copyMessage.textContent = 'Password copied!';
copyMessage.style.color = 'green';
copyMessage.style.display = 'none';
}, 3000);
});
}
function evaluateStrength(password) {
const bar = document.getElementById('strengthBar');
const text = document.getElementById('strengthText');
let score = 0;
if (password.length >= 12) score++;
if (password.length >= 16) score++;
if (/[A-Z]/.test(password)) score++;
if (/[a-z]/.test(password)) score++;
if (/[0-9]/.test(password)) score++;
if (/[^A-Za-z0-9]/.test(password)) score++;
if (!/(.)\1{2,}/.test(password)) score++;
let color = 'red', width = '25%', label = 'Weak';
if (score > 6) { color = 'green'; width = '100%'; label = 'Very Strong'; }
else if (score > 4) { color = 'gold'; width = '75%'; label = 'Strong'; }
else if (score > 2) { color = 'orange'; width = '50%'; label = 'Moderate'; }
const entropy = estimateEntropy(password);
bar.style.width = width;
bar.style.background = color;
text.textContent = `Strength: ${label} | Entropy: ${entropy} bits`;
text.style.color = color;
}
function estimateEntropy(password) {
let pool = 0;
if (/[a-z]/.test(password)) pool += 26;
if (/[A-Z]/.test(password)) pool += 26;
if (/[0-9]/.test(password)) pool += 10;
if (/[^A-Za-z0-9]/.test(password)) pool += 32;
if (pool === 0) return '0.00';
return (password.length * Math.log2(pool)).toFixed(2);
}
function toggleFeatureSection() {
const section = document.getElementById('featureSection');
const button = document.getElementById('toggleFeatures');
const isHidden = window.getComputedStyle(section).display === 'none';
section.style.display = isHidden ? 'block' : 'none';
button.textContent = isHidden ? '▼ Hide Features' : '▶ Show Features';
}
</script>
<a href=https://github.com/jasrasr/powershell/tree/main/Password-Generator-HTML>Development https://github.com/jasrasr/powershell/tree/main/Password-Generator-HTML</a>
</body>
</html>