-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
973 lines (817 loc) · 38.4 KB
/
index.html
File metadata and controls
973 lines (817 loc) · 38.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
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Password Strength Analyzer - Defensive Security Tool</title>
<style>
* {
box-sizing: border-box;
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}
body {
background: linear-gradient(135deg, #0f2027 0%, #203a43 50%, #2c5364 100%);
color: #e0e0e0;
min-height: 100vh;
padding: 20px;
margin: 0;
}
.container {
max-width: 1200px;
margin: 0 auto;
display: grid;
grid-template-columns: 1fr 1fr;
gap: 30px;
}
@media (max-width: 900px) {
.container {
grid-template-columns: 1fr;
}
}
.card {
background: rgba(25, 35, 45, 0.9);
border-radius: 12px;
padding: 25px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(100, 150, 200, 0.2);
}
h1, h2, h3 {
color: #4fc3f7;
margin-top: 0;
}
h1 {
text-align: center;
grid-column: 1 / -1;
padding-bottom: 20px;
border-bottom: 2px solid rgba(79, 195, 247, 0.3);
}
.disclaimer {
background: rgba(244, 67, 54, 0.15);
border-left: 4px solid #f44336;
padding: 15px;
margin: 20px 0;
border-radius: 0 8px 8px 0;
grid-column: 1 / -1;
}
.input-section {
display: flex;
flex-direction: column;
gap: 15px;
}
input[type="password"], input[type="text"] {
padding: 15px;
background: rgba(10, 20, 30, 0.8);
border: 2px solid rgba(100, 150, 200, 0.3);
border-radius: 8px;
color: white;
font-size: 16px;
transition: all 0.3s;
}
input[type="password"]:focus, input[type="text"]:focus {
outline: none;
border-color: #4fc3f7;
box-shadow: 0 0 15px rgba(79, 195, 247, 0.2);
}
button {
background: linear-gradient(135deg, #1565c0 0%, #0d47a1 100%);
color: white;
border: none;
padding: 15px;
border-radius: 8px;
cursor: pointer;
font-size: 16px;
font-weight: bold;
transition: all 0.3s;
margin: 5px 0;
}
button:hover {
background: linear-gradient(135deg, #1976d2 0%, #1565c0 100%);
transform: translateY(-2px);
box-shadow: 0 5px 15px rgba(21, 101, 192, 0.4);
}
.strength-meter {
height: 20px;
background: rgba(255, 255, 255, 0.1);
border-radius: 10px;
overflow: hidden;
margin: 20px 0;
position: relative;
}
.strength-fill {
height: 100%;
width: 0%;
border-radius: 10px;
transition: width 0.5s ease, background 0.5s ease;
}
.strength-text {
position: absolute;
width: 100%;
text-align: center;
font-weight: bold;
color: white;
text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.8);
}
.checklist {
display: flex;
flex-direction: column;
gap: 8px;
margin: 15px 0;
}
.checklist-item {
display: flex;
align-items: center;
gap: 10px;
}
.checklist-icon {
width: 20px;
height: 20px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: bold;
}
.icon-valid {
background: #4caf50;
}
.icon-invalid {
background: #f44336;
}
.attack-simulation {
background: rgba(244, 67, 54, 0.1);
border-radius: 8px;
padding: 15px;
margin: 15px 0;
border: 1px solid rgba(244, 67, 54, 0.3);
}
.simulation-results {
display: none;
}
.time-estimate {
font-size: 24px;
font-weight: bold;
color: #ff9800;
text-align: center;
padding: 10px;
background: rgba(255, 152, 0, 0.1);
border-radius: 8px;
margin: 10px 0;
}
.attack-method {
background: rgba(30, 40, 50, 0.8);
padding: 12px;
border-radius: 6px;
margin: 10px 0;
border-left: 4px solid #ff9800;
}
.progress-bar {
height: 10px;
background: rgba(255, 255, 255, 0.1);
border-radius: 5px;
overflow: hidden;
margin: 10px 0;
}
.progress-fill {
height: 100%;
background: linear-gradient(90deg, #ff5722, #ff9800);
width: 0%;
transition: width 1s ease;
}
.tooltip {
cursor: help;
border-bottom: 1px dashed #4fc3f7;
}
.password-examples {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-top: 15px;
}
.example {
padding: 10px;
background: rgba(255, 255, 255, 0.05);
border-radius: 6px;
cursor: pointer;
transition: all 0.2s;
text-align: center;
}
.example:hover {
background: rgba(79, 195, 247, 0.2);
}
.info-box {
background: rgba(79, 195, 247, 0.1);
border-left: 4px solid #4fc3f7;
padding: 15px;
margin: 15px 0;
border-radius: 0 8px 8px 0;
}
footer {
text-align: center;
margin-top: 30px;
padding-top: 20px;
border-top: 1px solid rgba(255, 255, 255, 0.1);
grid-column: 1 / -1;
font-size: 14px;
color: #aaa;
}
.tab-container {
display: flex;
gap: 5px;
margin-bottom: 20px;
}
.tab {
flex: 1;
padding: 12px;
background: rgba(30, 40, 50, 0.8);
border: none;
color: #ccc;
cursor: pointer;
border-radius: 6px 6px 0 0;
transition: all 0.3s;
}
.tab.active {
background: rgba(25, 35, 45, 0.9);
color: #4fc3f7;
font-weight: bold;
}
.tab-content {
display: none;
}
.tab-content.active {
display: block;
}
</style>
</head>
<body>
<div class="container">
<h1>🔐 Password Strength Analyzer with Security Simulation</h1>
<div class="disclaimer">
<strong>⚠️ IMPORTANT DISCLAIMER:</strong> This tool operates entirely in your browser. No passwords are transmitted or stored.
This is for <strong>defensive security education only</strong> to demonstrate how attackers exploit weak passwords.
</div>
<div class="card">
<div class="tab-container">
<button class="tab active" onclick="switchTab('analyzer')">Password Analyzer</button>
<button class="tab" onclick="switchTab('simulation')">Attack Simulation</button>
<button class="tab" onclick="switchTab('education')">Security Education</button>
</div>
<div id="analyzer" class="tab-content active">
<h2>Password Strength Analysis</h2>
<div class="input-section">
<input type="password" id="passwordInput" placeholder="Enter a password to analyze" autocomplete="off">
<button onclick="analyzePassword()">Analyze Password</button>
<button onclick="togglePasswordVisibility()" style="background: rgba(100, 150, 200, 0.3);">👁️ Show/Hide Password</button>
</div>
<div id="strengthResults" style="display: none;">
<h3>Strength Assessment</h3>
<div class="strength-meter">
<div class="strength-fill" id="strengthFill"></div>
<div class="strength-text" id="strengthText"></div>
</div>
<div class="checklist" id="checklist"></div>
<div class="info-box">
<strong>Password Score:</strong> <span id="score">0</span>/100
<br>
<strong>Estimated Cracking Time:</strong> <span id="crackTime">Instant</span>
</div>
<h3>Common Attack Vulnerabilities</h3>
<div id="vulnerabilities"></div>
</div>
<div class="password-examples">
<div class="example" onclick="testExample('password123')">Test: password123</div>
<div class="example" onclick="testExample('123456')">Test: 123456</div>
<div class="example" onclick="testExample('qwerty')">Test: qwerty</div>
<div class="example" onclick="testExample('Tr0ub4dour&3')">Test: Tr0ub4dour&3</div>
<div class="example" onclick="testExample('CorrectHorseBatteryStaple')">Test: CorrectHorseBatteryStaple</div>
<div class="example" onclick="testExample('X&$9pL2@qF!n')">Test: X&$9pL2@qF!n</div>
</div>
</div>
<div id="simulation" class="tab-content">
<h2>Offensive Security Simulation</h2>
<p>This simulation demonstrates how attackers attempt to crack passwords. <strong>No actual attack is performed.</strong></p>
<div class="input-section">
<input type="text" id="attackPassword" placeholder="Enter password to simulate attack against">
<button onclick="runAttackSimulation()">Run Attack Simulation</button>
</div>
<div id="simulationResults" class="simulation-results">
<h3>Attack Simulation Results</h3>
<div class="attack-simulation">
<h4>Dictionary Attack</h4>
<div class="attack-method">
<strong>Method:</strong> Checks against 10,000 common passwords
<div class="progress-bar">
<div class="progress-fill" id="dictProgress"></div>
</div>
<div id="dictResult">Status: Not attempted</div>
</div>
<h4>Brute Force Attack</h4>
<div class="attack-method">
<strong>Method:</strong> Systematic character-by-character guessing
<div class="progress-bar">
<div class="progress-fill" id="bruteProgress"></div>
</div>
<div id="bruteResult">Status: Not attempted</div>
</div>
<h4>Hybrid Attack</h4>
<div class="attack-method">
<strong>Method:</strong> Dictionary words with character substitutions
<div class="progress-bar">
<div class="progress-fill" id="hybridProgress"></div>
</div>
<div id="hybridResult">Status: Not attempted</div>
</div>
</div>
<div class="time-estimate" id="timeEstimate">
Estimated cracking time: Loading...
</div>
<div class="info-box">
<strong>Note:</strong> Actual attack times vary based on hardware, hashing algorithms, and system security measures.
This simulation is for educational purposes only.
</div>
</div>
</div>
<div id="education" class="tab-content">
<h2>Password Security Education</h2>
<div class="info-box">
<h3>How Attackers Crack Passwords</h3>
<p>Attackers use multiple techniques to exploit weak passwords:</p>
<ul>
<li><strong>Dictionary Attacks:</strong> Trying common words and passwords from lists</li>
<li><strong>Brute Force:</strong> Trying every possible character combination</li>
<li><strong>Hybrid Attacks:</strong> Combining dictionary words with variations (p@ssw0rd, password123)</li>
<li><strong>Credential Stuffing:</strong> Using leaked passwords from other breaches</li>
<li><strong>Social Engineering:</strong> Guessing based on personal information</li>
</ul>
</div>
<div class="info-box">
<h3>Creating Strong Passwords</h3>
<p><strong>Do:</strong></p>
<ul>
<li>Use at least 12-16 characters</li>
<li>Combine uppercase, lowercase, numbers, and symbols</li>
<li>Use passphrases (e.g., "CorrectHorseBatteryStaple")</li>
<li>Use unique passwords for every account</li>
<li>Use a password manager</li>
</ul>
<p><strong>Don't:</strong></p>
<ul>
<li>Use personal information (names, birthdays)</li>
<li>Use common words or patterns</li>
<li>Reuse passwords across sites</li>
<li>Use simple substitutions (p@ssw0rd)</li>
</ul>
</div>
<div class="info-box">
<h3>Additional Security Measures</h3>
<ul>
<li><strong>Two-Factor Authentication (2FA):</strong> Adds an extra layer of security</li>
<li><strong>Password Managers:</strong> Generate and store complex passwords</li>
<li><strong>Regular Updates:</strong> Change passwords periodically</li>
<li><strong>Breach Monitoring:</strong> Check if your accounts appear in data breaches</li>
<li><strong>Security Questions:</strong> Use random answers stored in your password manager</li>
</ul>
</div>
</div>
</div>
<div class="card">
<h2>Password Analysis Details</h2>
<div id="entropySection" style="display: none;">
<h3>Password Entropy: <span id="entropyValue">0</span> bits</h3>
<div class="progress-bar">
<div class="progress-fill" id="entropyProgress"></div>
</div>
<p>Entropy measures password randomness. Higher entropy = harder to crack.</p>
<h3>Character Composition</h3>
<div id="composition"></div>
<h3>Pattern Detection</h3>
<div id="patterns"></div>
<h3>Defensive Recommendations</h3>
<div id="recommendations"></div>
</div>
<div id="placeholderText">
<p>Enter a password to see detailed analysis of its strength, vulnerabilities, and defensive recommendations.</p>
<p>This tool helps you understand what makes passwords strong or weak from a defensive security perspective.</p>
</div>
</div>
<footer>
<p>🔒 <strong>Defensive Security Education Tool</strong> | This tool runs entirely in your browser - no data is sent to any server.</p>
<p>Use this knowledge to strengthen your own passwords and understand attacker methodologies for defensive purposes only.</p>
</footer>
</div>
<script>
// Common password lists for simulation
const commonPasswords = [
'password', '123456', '12345678', '1234', 'qwerty', '12345',
'dragon', 'football', 'baseball', 'welcome', 'abc123', '111111',
'mustang', 'access', 'shadow', 'michael', 'superman', '696969',
'123123', 'batman', 'trustno1', 'monkey', 'letmein', 'sunshine',
'master', 'admin', 'password1', 'hello', 'charlie', 'jordan'
];
function switchTab(tabName) {
// Hide all tabs
document.querySelectorAll('.tab-content').forEach(tab => {
tab.classList.remove('active');
});
// Deactivate all tab buttons
document.querySelectorAll('.tab').forEach(tab => {
tab.classList.remove('active');
});
// Show selected tab
document.getElementById(tabName).classList.add('active');
// Activate corresponding button
event.target.classList.add('active');
}
function analyzePassword() {
const password = document.getElementById('passwordInput').value;
if (!password) {
alert('Please enter a password to analyze');
return;
}
// Calculate password strength
const analysis = analyzePasswordStrength(password);
// Update UI
updateStrengthUI(analysis);
updateChecklist(analysis);
updateVulnerabilities(analysis);
updateEntropyAnalysis(analysis);
updateCompositionAnalysis(password);
updatePatternDetection(password);
updateRecommendations(analysis);
// Show results
document.getElementById('strengthResults').style.display = 'block';
document.getElementById('entropySection').style.display = 'block';
document.getElementById('placeholderText').style.display = 'none';
}
function analyzePasswordStrength(password) {
let score = 0;
const feedback = [];
const vulnerabilities = [];
// Length check
if (password.length >= 16) score += 30;
else if (password.length >= 12) score += 25;
else if (password.length >= 8) score += 15;
else if (password.length >= 6) score += 5;
else vulnerabilities.push('Too short (less than 6 characters)');
// Character variety checks
const hasLower = /[a-z]/.test(password);
const hasUpper = /[A-Z]/.test(password);
const hasNumbers = /\d/.test(password);
const hasSpecial = /[^A-Za-z0-9]/.test(password);
if (hasLower) score += 5;
if (hasUpper) score += 5;
if (hasNumbers) score += 10;
if (hasSpecial) score += 15;
// Common password check
if (commonPasswords.includes(password.toLowerCase())) {
score = Math.min(score, 10);
vulnerabilities.push('Common password (easily guessable)');
}
// Sequential characters check
if (/(abc|bcd|cde|def|efg|fgh|ghi|hij|ijk|jkl|klm|lmn|mno|nop|opq|pqr|qrs|rst|stu|tuv|uvw|vwx|wxy|xyz|012|123|234|345|456|567|678|789)/i.test(password)) {
score -= 15;
vulnerabilities.push('Contains sequential characters');
}
// Repeated characters check
if (/(.)\1{2,}/.test(password)) {
score -= 10;
vulnerabilities.push('Repeated characters (e.g., aaa, 111)');
}
// Common patterns
if (/^(password|admin|welcome|qwerty|123456)/i.test(password)) {
score = Math.min(score, 5);
vulnerabilities.push('Starts with common weak pattern');
}
// Entropy calculation
let charsetSize = 0;
if (hasLower) charsetSize += 26;
if (hasUpper) charsetSize += 26;
if (hasNumbers) charsetSize += 10;
if (hasSpecial) charsetSize += 32; // Common special characters
const entropy = password.length * Math.log2(charsetSize || 1);
// Adjust score based on entropy
if (entropy > 100) score += 20;
else if (entropy > 70) score += 15;
else if (entropy > 50) score += 10;
else if (entropy > 30) score += 5;
// Ensure score is within bounds
score = Math.max(0, Math.min(100, score));
// Crack time estimation
let crackTime = 'Instant';
const guessesPerSecond = 1000000000; // 1 billion guesses/sec (modern GPU)
const possibleCombinations = Math.pow(charsetSize, password.length);
const secondsToCrack = possibleCombinations / guessesPerSecond;
if (secondsToCrack < 1) crackTime = 'Less than a second';
else if (secondsToCrack < 60) crackTime = 'Seconds';
else if (secondsToCrack < 3600) crackTime = 'Minutes';
else if (secondsToCrack < 86400) crackTime = 'Hours';
else if (secondsToCrack < 2592000) crackTime = 'Days';
else if (secondsToCrack < 31536000) crackTime = 'Months';
else if (secondsToCrack < 315360000) crackTime = 'Years';
else if (secondsToCrack < 3153600000) crackTime = 'Decades';
else crackTime = 'Centuries';
return {
score,
length: password.length,
hasLower,
hasUpper,
hasNumbers,
hasSpecial,
entropy,
crackTime,
vulnerabilities,
isCommon: commonPasswords.includes(password.toLowerCase())
};
}
function updateStrengthUI(analysis) {
const strengthFill = document.getElementById('strengthFill');
const strengthText = document.getElementById('strengthText');
const scoreElement = document.getElementById('score');
const crackTimeElement = document.getElementById('crackTime');
// Update score
scoreElement.textContent = analysis.score;
// Update crack time
crackTimeElement.textContent = analysis.crackTime;
// Update strength meter
let strengthColor, strengthLabel;
if (analysis.score >= 80) {
strengthColor = '#4CAF50'; // Green
strengthLabel = 'VERY STRONG';
} else if (analysis.score >= 60) {
strengthColor = '#8BC34A'; // Light green
strengthLabel = 'STRONG';
} else if (analysis.score >= 40) {
strengthColor = '#FFC107'; // Yellow
strengthLabel = 'MODERATE';
} else if (analysis.score >= 20) {
strengthColor = '#FF9800'; // Orange
strengthLabel = 'WEAK';
} else {
strengthColor = '#F44336'; // Red
strengthLabel = 'VERY WEAK';
}
strengthFill.style.width = `${analysis.score}%`;
strengthFill.style.background = strengthColor;
strengthText.textContent = strengthLabel;
}
function updateChecklist(analysis) {
const checklist = document.getElementById('checklist');
checklist.innerHTML = '';
const checks = [
{ label: `Length: ${analysis.length} characters (12+ recommended)`, valid: analysis.length >= 12 },
{ label: 'Contains lowercase letters', valid: analysis.hasLower },
{ label: 'Contains uppercase letters', valid: analysis.hasUpper },
{ label: 'Contains numbers', valid: analysis.hasNumbers },
{ label: 'Contains special characters', valid: analysis.hasSpecial },
{ label: 'Not a common password', valid: !analysis.isCommon },
{ label: 'High entropy (randomness)', valid: analysis.entropy > 60 }
];
checks.forEach(check => {
const item = document.createElement('div');
item.className = 'checklist-item';
const icon = document.createElement('div');
icon.className = `checklist-icon ${check.valid ? 'icon-valid' : 'icon-invalid'}`;
icon.textContent = check.valid ? '✓' : '✗';
const label = document.createElement('span');
label.textContent = check.label;
item.appendChild(icon);
item.appendChild(label);
checklist.appendChild(item);
});
}
function updateVulnerabilities(analysis) {
const vulnerabilitiesElement = document.getElementById('vulnerabilities');
if (analysis.vulnerabilities.length === 0) {
vulnerabilitiesElement.innerHTML = '<div class="checklist-item"><div class="checklist-icon icon-valid">✓</div><span>No major vulnerabilities detected</span></div>';
return;
}
vulnerabilitiesElement.innerHTML = '';
analysis.vulnerabilities.forEach(vuln => {
const item = document.createElement('div');
item.className = 'checklist-item';
const icon = document.createElement('div');
icon.className = 'checklist-icon icon-invalid';
icon.textContent = '!';
const label = document.createElement('span');
label.textContent = vuln;
item.appendChild(icon);
item.appendChild(label);
vulnerabilitiesElement.appendChild(item);
});
}
function updateEntropyAnalysis(analysis) {
document.getElementById('entropyValue').textContent = analysis.entropy.toFixed(1);
const entropyProgress = document.getElementById('entropyProgress');
let progressPercent = (analysis.entropy / 100) * 100;
if (progressPercent > 100) progressPercent = 100;
entropyProgress.style.width = `${progressPercent}%`;
}
function updateCompositionAnalysis(password) {
const compositionElement = document.getElementById('composition');
let lowercase = 0, uppercase = 0, numbers = 0, special = 0;
for (let char of password) {
if (/[a-z]/.test(char)) lowercase++;
else if (/[A-Z]/.test(char)) uppercase++;
else if (/\d/.test(char)) numbers++;
else special++;
}
compositionElement.innerHTML = `
<p>Lowercase: ${lowercase} | Uppercase: ${uppercase} | Numbers: ${numbers} | Special: ${special}</p>
<p>Total characters: ${password.length}</p>
`;
}
function updatePatternDetection(password) {
const patternsElement = document.getElementById('patterns');
const patterns = [];
// Check for keyboard patterns
const keyboardPatterns = ['qwerty', 'asdfgh', 'zxcvbn', '123456', 'password'];
keyboardPatterns.forEach(pattern => {
if (password.toLowerCase().includes(pattern)) {
patterns.push(`Contains keyboard pattern: "${pattern}"`);
}
});
// Check for repeated sequences
const repeatPattern = /(.{2,})\1+/;
if (repeatPattern.test(password)) {
patterns.push('Contains repeated sequences');
}
// Check for common substitutions
const commonSubstitutions = {
'a': '@', 's': '$', 'e': '3', 'o': '0', 'i': '1', 'l': '1'
};
let hasSimpleSubstitution = false;
const lowerPass = password.toLowerCase();
for (let sub in commonSubstitutions) {
if (lowerPass.includes(commonSubstitutions[sub]) && lowerPass.includes(sub)) {
hasSimpleSubstitution = true;
}
}
if (hasSimpleSubstitution) {
patterns.push('Uses predictable character substitutions (leetspeak)');
}
if (patterns.length === 0) {
patternsElement.innerHTML = '<p>No obvious patterns detected ✓</p>';
} else {
patternsElement.innerHTML = '<p>' + patterns.join('<br>') + '</p>';
}
}
function updateRecommendations(analysis) {
const recommendationsElement = document.getElementById('recommendations');
const recommendations = [];
if (analysis.length < 12) {
recommendations.push('Increase password length to at least 12 characters');
}
if (!analysis.hasLower) {
recommendations.push('Add lowercase letters');
}
if (!analysis.hasUpper) {
recommendations.push('Add uppercase letters');
}
if (!analysis.hasNumbers) {
recommendations.push('Add numbers');
}
if (!analysis.hasSpecial) {
recommendations.push('Add special characters (!@#$%^&*, etc.)');
}
if (analysis.entropy < 60) {
recommendations.push('Increase randomness - avoid predictable patterns');
}
if (analysis.isCommon) {
recommendations.push('Choose a less common password - avoid dictionary words');
}
if (recommendations.length === 0) {
recommendationsElement.innerHTML = '<p>Your password meets all basic security requirements. Consider using a password manager for maximum security.</p>';
} else {
recommendationsElement.innerHTML = '<p><strong>Recommendations to improve:</strong></p><ul>' +
recommendations.map(rec => `<li>${rec}</li>`).join('') + '</ul>';
}
}
function testExample(password) {
document.getElementById('passwordInput').value = password;
analyzePassword();
}
function togglePasswordVisibility() {
const input = document.getElementById('passwordInput');
if (input.type === 'password') {
input.type = 'text';
} else {
input.type = 'password';
}
}
async function runAttackSimulation() {
const password = document.getElementById('attackPassword').value;
if (!password) {
alert('Please enter a password to simulate attack against');
return;
}
document.getElementById('simulationResults').style.display = 'block';
// Reset progress bars
document.getElementById('dictProgress').style.width = '0%';
document.getElementById('bruteProgress').style.width = '0%';
document.getElementById('hybridProgress').style.width = '0%';
document.getElementById('dictResult').textContent = 'Status: Running...';
document.getElementById('bruteResult').textContent = 'Status: Running...';
document.getElementById('hybridResult').textContent = 'Status: Running...';
// Simulate dictionary attack
await simulateAttack('dict', password);
// Simulate hybrid attack
await simulateAttack('hybrid', password);
// Simulate brute force attack
await simulateAttack('brute', password);
// Calculate and display time estimate
updateTimeEstimate(password);
}
async function simulateAttack(type, password) {
const totalSteps = 100;
for (let i = 0; i <= totalSteps; i++) {
await new Promise(resolve => setTimeout(resolve, 20));
let progressElement, resultElement;
switch(type) {
case 'dict':
progressElement = document.getElementById('dictProgress');
resultElement = document.getElementById('dictResult');
break;
case 'hybrid':
progressElement = document.getElementById('hybridProgress');
resultElement = document.getElementById('hybridResult');
break;
case 'brute':
progressElement = document.getElementById('bruteProgress');
resultElement = document.getElementById('bruteResult');
break;
}
progressElement.style.width = `${i}%`;
// Simulate finding the password at different points
if (type === 'dict' && i >= 30 && commonPasswords.includes(password.toLowerCase())) {
resultElement.textContent = 'Status: CRACKED (found in dictionary)';
resultElement.style.color = '#f44336';
return;
}
if (type === 'hybrid' && i >= 60 && password.length < 8) {
resultElement.textContent = 'Status: CRACKED (hybrid attack successful)';
resultElement.style.color = '#f44336';
return;
}
if (type === 'brute' && i >= 90 && password.length < 6) {
resultElement.textContent = 'Status: CRACKED (brute force successful)';
resultElement.style.color = '#f44336';
return;
}
}
// If not cracked
let resultElement;
switch(type) {
case 'dict': resultElement = document.getElementById('dictResult'); break;
case 'hybrid': resultElement = document.getElementById('hybridResult'); break;
case 'brute': resultElement = document.getElementById('bruteResult'); break;
}
resultElement.textContent = 'Status: Failed (password resistant to this attack)';
resultElement.style.color = '#4caf50';
}
function updateTimeEstimate(password) {
const timeEstimateElement = document.getElementById('timeEstimate');
// Simple estimation based on password characteristics
let estimate = 'Centuries';
const length = password.length;
const hasLower = /[a-z]/.test(password);
const hasUpper = /[A-Z]/.test(password);
const hasNumbers = /\d/.test(password);
const hasSpecial = /[^A-Za-z0-9]/.test(password);
let charsetSize = 0;
if (hasLower) charsetSize += 26;
if (hasUpper) charsetSize += 26;
if (hasNumbers) charsetSize += 10;
if (hasSpecial) charsetSize += 32;
// Common password check
if (commonPasswords.includes(password.toLowerCase())) {
estimate = 'Less than 1 second';
} else if (length < 6) {
estimate = 'Seconds to minutes';
} else if (length < 8) {
estimate = 'Minutes to hours';
} else if (length < 10) {
if (charsetSize < 30) estimate = 'Hours to days';
else estimate = 'Days to months';
} else if (length < 12) {
if (charsetSize < 40) estimate = 'Months to years';
else estimate = 'Years to decades';
} else if (length >= 12) {
if (charsetSize >= 60) estimate = 'Decades to centuries';
else estimate = 'Years to decades';
}
timeEstimateElement.textContent = `Estimated cracking time with modern hardware: ${estimate}`;
// Color code based on time
if (estimate.includes('second') || estimate.includes('minute') || estimate.includes('hour')) {
timeEstimateElement.style.color = '#f44336';
} else if (estimate.includes('day') || estimate.includes('month')) {
timeEstimateElement.style.color = '#ff9800';
} else {
timeEstimateElement.style.color = '#4caf50';
}
}
// Initialize with an example
window.onload = function() {
testExample('password123');
};
</script>
</body>
</html>