-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRandomPasswordGenerator.html
174 lines (149 loc) · 5.6 KB
/
RandomPasswordGenerator.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
<!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>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
margin: 0;
background-color: #f0f2f5;
}
.container {
background-color: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
width: 90%;
max-width: 400px;
}
h1 {
text-align: center;
color: #333;
margin-bottom: 1.5rem;
}
.password-display {
background-color: #f8f9fa;
padding: 1rem;
border: 1px solid #dee2e6;
border-radius: 5px;
margin-bottom: 1rem;
font-family: monospace;
font-size: 1.2rem;
word-break: break-all;
min-height: 2.5rem;
}
.controls {
display: flex;
flex-direction: column;
gap: 1rem;
}
.control-group {
display: flex;
justify-content: space-between;
align-items: center;
}
input[type="checkbox"] {
width: 1.2rem;
height: 1.2rem;
}
input[type="range"] {
width: 100%;
margin: 1rem 0;
}
button {
background-color: #007bff;
color: white;
border: none;
padding: 0.8rem;
border-radius: 5px;
cursor: pointer;
font-size: 1rem;
transition: background-color 0.2s;
}
button:hover {
background-color: #0056b3;
}
.length-display {
text-align: center;
font-size: 1.1rem;
color: #666;
}
</style>
</head>
<body>
<div class="container">
<h1>Password Generator</h1>
<div class="password-display" id="passwordDisplay">Your password will appear here</div>
<div class="controls">
<div class="control-group">
<label>Password Length: <span id="lengthValue">12</span></label>
<input type="range" min="8" max="32" value="12" id="lengthSlider">
</div>
<div class="control-group">
<label for="uppercase">Include Uppercase</label>
<input type="checkbox" id="uppercase" checked>
</div>
<div class="control-group">
<label for="numbers">Include Numbers</label>
<input type="checkbox" id="numbers" checked>
</div>
<div class="control-group">
<label for="symbols">Include Symbols</label>
<input type="checkbox" id="symbols" checked>
</div>
<button onclick="generatePassword()">Generate Password</button>
</div>
</div>
<script>
const lengthSlider = document.getElementById('lengthSlider');
const lengthValue = document.getElementById('lengthValue');
const passwordDisplay = document.getElementById('passwordDisplay');
lengthSlider.addEventListener('input', (e) => {
lengthValue.textContent = e.target.value;
});
function generatePassword() {
const length = parseInt(lengthSlider.value);
const includeUppercase = document.getElementById('uppercase').checked;
const includeNumbers = document.getElementById('numbers').checked;
const includeSymbols = document.getElementById('symbols').checked;
const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const numberChars = '0123456789';
const symbolChars = '!@#$%^&*()_+-=[]{}|;:,.<>?';
let allowedChars = lowercaseChars;
if (includeUppercase) allowedChars += uppercaseChars;
if (includeNumbers) allowedChars += numberChars;
if (includeSymbols) allowedChars += symbolChars;
let password = '';
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * allowedChars.length);
password += allowedChars[randomIndex];
}
// Ensure at least one character from each selected category
if (includeUppercase) {
const randomIndex = Math.floor(Math.random() * uppercaseChars.length);
password = password.substring(1) + uppercaseChars[randomIndex];
}
if (includeNumbers) {
const randomIndex = Math.floor(Math.random() * numberChars.length);
password = password.substring(1) + numberChars[randomIndex];
}
if (includeSymbols) {
const randomIndex = Math.floor(Math.random() * symbolChars.length);
password = password.substring(1) + symbolChars[randomIndex];
}
// Shuffle the password
password = password.split('').sort(() => Math.random() - 0.5).join('');
passwordDisplay.textContent = password;
}
// Generate initial password
generatePassword();
</script>
</body>
</html>