-
Notifications
You must be signed in to change notification settings - Fork 0
/
Random-password-generator.html
107 lines (104 loc) · 3.48 KB
/
Random-password-generator.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Random Password Generator</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #333;
color: white;
}
.container {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
height: 100vh;
}
button {
padding: 10px 20px;
margin: 10px;
background-color: #007bff;
color: white;
border: none;
cursor: pointer;
}
input[type="number"] {
padding: 5px;
margin: 10px;
}
.password-box {
border: 1px solid #ccc;
padding: 10px;
margin: 20px;
background-color: #222;
}
.password-characters {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
h1 {
font-weight: bold;
color: #ff6600;
}
</style>
</head>
<body>
<div class="container">
<h1>Random Password Generator</h1>
<label for="length">Enter number of characters:</label>
<input type="number" id="length" min="1" max="20">
<br>
<label for="characters">Select characters to include:</label>
<div class="password-characters">
<input type="checkbox" id="lowercase" checked>
<label for="lowercase">Lowercase Letters</label>
<br>
<input type="checkbox" id="uppercase" checked>
<label for="uppercase">Uppercase Letters</label>
<br>
<input type="checkbox" id="numbers" checked>
<label for="numbers">Numbers</label>
<br>
<input type="checkbox" id="special" checked>
<label for="special">Special Characters</label>
</div>
<button onclick="generatePassword()">Generate Password</button>
<div class="password-box">
<p id="generatedPassword"></p>
<button onclick="copyToClipboard()" id="copyButton">Copy Password</button>
</div>
</div>
<script>
function generatePassword() {
const length = document.getElementById("length").value;
let charset = "";
if (document.getElementById("lowercase").checked) charset += "abcdefghijklmnopqrstuvwxyz";
if (document.getElementById("uppercase").checked) charset += "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (document.getElementById("numbers").checked) charset += "0123456789";
if (document.getElementById("special").checked) charset += "!@#$%^&*";
let password = "";
for (let i = 0; i < length; i++) {
const char = charset.charAt(Math.floor(Math.random() * charset.length));
password += char + "<br>";
}
document.getElementById("generatedPassword").innerHTML = password;
}
function copyToClipboard() {
const passwordText = document.getElementById("generatedPassword");
const textArea = document.createElement("textarea");
textArea.value = passwordText.innerText;
document.body.appendChild(textArea);
textArea.select();
document.execCommand("copy");
document.body.removeChild(textArea);
alert("Password copied to clipboard!");
}
</script>
</body>
</html>