-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
548 lines (473 loc) · 14 KB
/
index.html
File metadata and controls
548 lines (473 loc) · 14 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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<!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>
/* General page styling */
body {
font-family: Arial;
margin: 0;
padding: 15px;
background: #f0f0f5;
color: #222;
font-size: 14px;
}
h2 {
text-align: center;
margin-bottom: 15px;
font-size: 18px;
}
/* Main container for output and settings */
.container {
display: flex;
flex-direction: column;
gap: 10px;
max-width: 700px;
margin: 0 auto;
}
/* Settings and output sections styling */
.settings, .output-area {
background: #fff;
padding: 15px;
border-radius: 8px;
box-shadow: 0 3px 8px rgba(0,0,0,0.1);
}
/* Settings top row (mode and length) */
.settings-top {
display: flex;
gap: 15px;
margin-bottom: 0;
}
.settings-top > div {
flex: 1;
}
.settings-middle {
margin: 0 0 15px 0;
}
/* File input row */
.file-input-wrapper {
display: flex;
align-items: center;
gap: 8px;
}
.file-input-wrapper label {
margin: 0;
font-weight: bold;
font-size: 13px;
}
.file-input-wrapper input[type="file"] {
flex: 1;
font-size: 13px;
}
/* Bottom settings (checkboxes and sliders) */
.settings-bottom {
margin-top: 15px;
}
.settings label {
display: block;
margin: 8px 0 4px;
font-weight: bold;
font-size: 13px;
}
.settings input[type="checkbox"],
.settings input[type="radio"] {
margin-right: 3px;
}
.settings input[type="range"] {
width: 100%;
margin: 3px 0 1px;
}
.settings span {
font-size: 12px;
color: #555;
display: block;
margin-bottom: 10px;
}
/* Output display */
.output-area {
display: flex;
flex-direction: column;
align-items: stretch;
gap: 10px;
position: relative;
}
.output-display {
display: flex;
align-items: center;
gap: 10px;
}
#output {
flex: 1;
font-size: 1.2em;
font-weight: bold;
word-break: break-all;
padding: 10px;
border: 2px solid #ccc;
border-radius: 6px;
background: #f9f9f9;
text-align: center;
}
/* Buttons under output */
.output-buttons {
display: flex;
gap: 10px;
justify-content: flex-end;
margin-top: 0;
}
.output-buttons button {
font-size: 1em;
padding: 8px;
border: none;
border-radius: 6px;
cursor: pointer;
background: #4a90e2;
color: #fff;
flex: 1;
transition: background 0.2s;
}
.output-buttons button:hover {
background: #357ab7;
}
/* Dropdown select styling */
select {
padding: 4px;
font-size: 13px;
border-radius: 4px;
border: 1px solid #ccc;
}
/* Toast notification */
#toast {
position: absolute;
bottom: -15%;
left: 50%;
transform: translateX(-50%) translateY(15px);
padding: 8px 12px;
background: #4a90e2;
color: #fff;
border-radius: 6px;
text-align: center;
font-size: 13px;
opacity: 0;
transition: opacity 0.3s, transform 0.3s;
pointer-events: none;
}
#toast.show {
opacity: 1;
transform: translateX(-50%) translateY(0);
}
/* Mobile layout: comfortable sizing */
@media (max-width: 768px) {
body {
font-size: 16px;
padding: 18px;
}
h2 {
font-size: 22px;
margin-bottom: 18px;
}
.container {
max-width: 100%;
gap: 15px;
}
.settings, .output-area {
padding: 18px;
border-radius: 10px;
}
#output {
font-size: 1.6em;
padding: 14px;
}
.output-buttons button {
font-size: 1.1em;
padding: 12px;
}
select {
font-size: 1em;
padding: 6px;
}
input[type="range"] {
height: 24px;
}
input[type="checkbox"],
input[type="radio"] {
transform: scale(1.3);
margin-right: 6px;
}
.settings label {
font-size: 15px;
}
#toast {
font-size: 15px;
padding: 10px 14px;
}
.settings-top {
flex-direction: column;
gap: 15px;
}
}
</style>
</head>
<body>
<h2>Password Generator</h2>
<!-- Main container -->
<div class="container">
<!-- Output display area -->
<div class="output-area">
<div class="output-display">
<div id="output"></div>
</div>
<div class="output-buttons">
<button onclick="generatePassword()">⚡ Generate</button>
<button onclick="copyPassword()">📋 Copy</button>
</div>
<div id="toast"></div>
</div>
<!-- Settings area -->
<div class="settings">
<!-- Top row: mode and length -->
<div class="settings-top">
<div>
<label>Mode:</label>
<label><input type="radio" name="mode" value="jibberish"> Jibberish</label>
<label><input type="radio" name="mode" value="words" checked> Words</label>
</div>
<div>
<label for="length">Length:</label>
<select id="length">
<option>8</option>
<option>10</option>
<option>12</option>
<option>14</option>
<option selected>16</option>
<option>18</option>
<option>20</option>
<option>30</option>
</select>
</div>
</div>
<!-- Bottom row: checkboxes and sliders -->
<div class="settings-bottom">
<label><input type="checkbox" id="numbers" checked> Include Numbers (0-9)</label>
<label><input type="checkbox" id="symbols" checked> Include Symbols (!@#$%^&*()+)</label>
<label for="capitalMode">Capitalization Mode:</label>
<input type="range" id="capitalMode" min="1" max="2" value="1">
<span id="capitalModeLabel">First letter of every word</span>
<label for="symbolMode">Symbol/Number Mode:</label>
<input type="range" id="symbolMode" min="1" max="3" value="2">
<span id="symbolModeLabel">Similar looking numbers/letters</span>
<label for="similarStrength">Similar-Looking Strength:</label>
<input type="range" id="similarStrength" min="1" max="3" value="1">
<span id="similarStrengthLabel">Low</span>
</div>
</div>
<p style="text-align:center; margin-top:10px; font-size:14px; color:#555;">
Created by Jake Carter | 2025
<br>
Source Code @
<a href="https://github.com/JakeCarterDPM/PasswordGenerator" target="_blank" style="color:#007acc; text-decoration:none;">
GitHub
</a>
</p>
</div>
<!-- Script section -->
<script>
// Default word list
let defaultWords = ["sampleword","sampledrow","yoyojson"];
let words = JSON.parse(localStorage.getItem("words") || JSON.stringify(defaultWords));
let similarSymbols = true, similarNumbers = true;
// Try to load words-small-set.json if no word list stored
if (!localStorage.getItem("words")) {
fetch("words-small-set.json")
.then(response => {
if (!response.ok) throw new Error("Failed to load words-small-set.json");
return response.json();
})
.then(data => {
if (Array.isArray(data) && data.length) {
words = data;
localStorage.setItem("words", JSON.stringify(data));
generatePassword();
}
})
.catch(err => {
console.error("Error loading default word list:", err);
});
}
const letters = "abcdefghijklmnopqrstuvwxyz";
const numbers = "0123456789";
const symbols = "!@#$%^&*()+";
// Mapping for similar-looking characters
const similarMaps = {
symbols: [
{ i:"!", l:"1", s:"$" },
{ i:"!", l:"1", s:"$", a:"@", e:"3" },
{ i:"!", l:"1", s:"$", a:"@", e:"3", t:"+", o:"0", b:"8", g:"9" }
],
numbers: [
{ e:"3", o:"0" },
{ e:"3", o:"0", b:"8", g:"9" },
{ e:"3", o:"0", b:"8", g:"9", t:"+", a:"@" }
]
};
// Randomize letter case
const randomCase = c => Math.random() < 0.5 ? c.toLowerCase() : c.toUpperCase();
// Get a random character from pool
function getRandomChar(includeNumbers, includeSymbols) {
const pool = letters + (includeNumbers ? numbers : "") + (includeSymbols ? symbols : "");
const ch = pool[Math.floor(Math.random() * pool.length)];
return /[a-z]/i.test(ch) ? randomCase(ch) : ch;
}
// Insert extras between words
function insertExtrasBetweenWords(password, includeNumbers, includeSymbols) {
const extras = (includeNumbers ? numbers : "") + (includeSymbols ? symbols : "");
if (!extras) return password;
return password.split(" ").map((w,i,a) => i<a.length-1 ? w + extras[Math.floor(Math.random()*extras.length)] : w).join("");
}
// Replace similar characters based on strength
function replaceSimilar(password, type, strength) {
const map = similarMaps[type][strength-1];
const lettersToReplace = password.split("").map((c,i)=>({c,i})).filter(x=>map[x.c.toLowerCase()]);
let replaceCount = 0;
if(strength===1) replaceCount = Math.ceil(lettersToReplace.length * 0.25);
else if(strength===2) replaceCount = Math.ceil(lettersToReplace.length * 0.50);
else replaceCount = Math.ceil(lettersToReplace.length * 0.90);
const indices = [];
while(indices.length < replaceCount && lettersToReplace.length){
const idx = Math.floor(Math.random() * lettersToReplace.length);
indices.push(lettersToReplace[idx].i);
lettersToReplace.splice(idx, 1);
}
return password.split("").map((c,i) => indices.includes(i) ? map[c.toLowerCase()] || c : c).join("");
}
// Ensure password contains numbers/symbols if required
function ensureExtras(password, includeNumbers, includeSymbols) {
let attempts = 0;
while(includeNumbers && !/[0-9]/.test(password) && attempts<10){
const pos = Math.floor(Math.random()*password.length);
password = password.slice(0,pos) + numbers[Math.floor(Math.random()*numbers.length)] + password.slice(pos);
attempts++;
}
attempts = 0;
while(includeSymbols && !/[!@#$%^&*()+]/.test(password) && attempts<10){
const pos = Math.floor(Math.random()*password.length);
password = password.slice(0,pos) + symbols[Math.floor(Math.random()*symbols.length)] + password.slice(pos);
attempts++;
}
return password;
}
// Generate password
function generatePassword() {
const len = parseInt(document.getElementById("length").value);
const mode = document.querySelector("input[name='mode']:checked").value;
const includeNumbers = document.getElementById("numbers").checked;
const includeSymbols = document.getElementById("symbols").checked;
const symbolMode = parseInt(document.getElementById("symbolMode").value);
const capitalMode = parseInt(document.getElementById("capitalMode").value);
const strength = parseInt(document.getElementById("similarStrength").value);
let password = "";
if(mode==="words"){
let wordList = [];
while(wordList.join("").length < len){
let word = words[Math.floor(Math.random()*words.length)];
word = capitalMode===1 ? word[0].toUpperCase() + word.slice(1).toLowerCase()
: word.split("").map(c=>/[a-z]/i.test(c)?randomCase(c):c).join("");
wordList.push(word.replace(/\s+/g,""));
}
password = wordList.join("").slice(0,len);
if(symbolMode===1) password = insertExtrasBetweenWords(password, includeNumbers, includeSymbols).slice(0,len);
else if(symbolMode===2){
if(similarSymbols) password = replaceSimilar(password,"symbols",strength);
if(similarNumbers) password = replaceSimilar(password,"numbers",strength);
} else if(symbolMode===3){
const extras = (includeNumbers ? numbers : "") + (includeSymbols ? symbols : "");
if(extras.length) password = wordList.map(w=>w+extras[Math.floor(Math.random()*extras.length)]).join("").slice(0,len);
}
} else {
const prevNums = [];
while(password.length < len){
const ch = getRandomChar(includeNumbers, includeSymbols);
if(/[0-9]/.test(ch)){
const num = parseInt(ch);
if(prevNums.length>=2 && prevNums[0]+1===prevNums[1] && prevNums[1]+1===num) continue;
prevNums.push(num); if(prevNums.length>2) prevNums.shift();
}
password += /[a-z]/i.test(ch)?randomCase(ch):ch;
}
if(symbolMode===2){
if(similarSymbols) password = replaceSimilar(password,"symbols",strength);
if(similarNumbers) password = replaceSimilar(password,"numbers",strength);
}
}
password = ensureExtras(password, includeNumbers, includeSymbols);
password = password.slice(0,len);
// Update output display
document.getElementById("output").textContent = password;
}
// Copy password to clipboard
function copyPassword() {
navigator.clipboard.writeText(document.getElementById("output").textContent)
.then(() => showToast("Password copied!"))
.catch(() => showToast("Failed to copy password."));
}
// Show temporary toast notification
function showToast(message) {
const toast = document.getElementById("toast");
toast.textContent = message;
toast.classList.add("show");
setTimeout(() => {
toast.classList.remove("show");
}, 1000);
}
// Toggle settings for similar symbols/numbers
function toggleSimilarSymbols() {
similarSymbols = document.getElementById("symbols").checked;
updateSymbolLabel();
}
function toggleSimilarNumbers() {
similarNumbers = document.getElementById("numbers").checked;
}
// Update labels for sliders
function updateSymbolLabel(){
const val = parseInt(document.getElementById("symbolMode").value);
document.getElementById("symbolModeLabel").textContent = val===1?"Added between words":val===2?"Similar looking numbers/letters":"Randomly throughout";
updateStrengthState();
}
function updateCapitalLabel(){
document.getElementById("capitalModeLabel").textContent = parseInt(document.getElementById("capitalMode").value)===1?"First letter of every word":"Random";
}
function updateStrengthLabel(){
const val=parseInt(document.getElementById("similarStrength").value);
document.getElementById("similarStrengthLabel").textContent = val===1?"Low (25% Changed)":val===2?"Medium (50% Changed)":"High (90% Changed)";
}
function updateStrengthState() {
const symbolMode = parseInt(document.getElementById("symbolMode").value);
document.getElementById("similarStrength").disabled = (symbolMode !== 2);
}
// Event listeners for sliders and checkboxes
document.getElementById("symbolMode").addEventListener("input", updateSymbolLabel);
document.getElementById("capitalMode").addEventListener("input", updateCapitalLabel);
document.getElementById("similarStrength").addEventListener("input", updateStrengthLabel);
document.getElementById("symbols").addEventListener("change", toggleSimilarSymbols);
document.getElementById("numbers").addEventListener("change", toggleSimilarNumbers);
// Initialize settings and generate initial password on load
window.onload = () => {
document.getElementById("length").value = "16";
document.querySelector("input[name='mode'][value='words']").checked = true;
document.getElementById("numbers").checked = true;
document.getElementById("symbols").checked = true;
document.getElementById("symbolMode").value = 2;
document.getElementById("capitalMode").value = 1;
document.getElementById("similarStrength").value = 1;
toggleSimilarSymbols();
toggleSimilarNumbers();
updateSymbolLabel();
updateCapitalLabel();
updateStrengthLabel();
updateStrengthState();
generatePassword();
};
</script>
</body>
</html>