Skip to content

Commit 846cabd

Browse files
authored
Added Password tool
1 parent e44d9df commit 846cabd

4 files changed

Lines changed: 120 additions & 0 deletions

File tree

index.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ <h2>Calculator</h2>
2323
<p>Perform quick calculations.</p>
2424
<a href="tools/calculator.html" class="btn">Open</a>
2525
</div>
26+
<div class="tool-card">
27+
<h2>Password Generator</h2>
28+
<p>Create strong and secure passwords.</p>
29+
<a href="tools/password.html" class="btn">Open</a>
30+
</div>
2631
</main>
2732

2833
<footer>

tools/password.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
.password-container {
2+
max-width: 400px;
3+
margin: 2rem auto;
4+
background: white;
5+
padding: 1.5rem;
6+
border-radius: 12px;
7+
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
8+
}
9+
10+
.password-box {
11+
margin-bottom: 1.2rem;
12+
}
13+
14+
.password-box label {
15+
display: block;
16+
margin-bottom: 0.3rem;
17+
font-weight: bold;
18+
}
19+
20+
#result {
21+
width: 70%;
22+
padding: 0.6rem;
23+
font-size: 1rem;
24+
border: 1px solid #ccc;
25+
border-radius: 8px;
26+
}
27+
28+
#copyBtn {
29+
padding: 0.6rem 1rem;
30+
margin-left: 0.5rem;
31+
}

tools/password.html

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Password Generator</title>
7+
<link rel="stylesheet" href="../css/style.css">
8+
<link rel="stylesheet" href="password.css">
9+
</head>
10+
<body>
11+
<header>
12+
<h1>Password Generator</h1>
13+
<a href="../index.html" class="btn">← Back</a>
14+
</header>
15+
16+
<main class="password-container">
17+
<div class="password-box">
18+
<label for="length">Length:</label>
19+
<input type="number" id="length" value="12" min="4" max="50">
20+
</div>
21+
22+
<div class="password-box">
23+
<label><input type="checkbox" id="lowercase" checked> Lowercase (a-z)</label><br>
24+
<label><input type="checkbox" id="uppercase" checked> Uppercase (A-Z)</label><br>
25+
<label><input type="checkbox" id="numbers" checked> Numbers (0-9)</label><br>
26+
<label><input type="checkbox" id="symbols"> Symbols (!@#$%)</label>
27+
</div>
28+
29+
<div class="password-box">
30+
<button id="generateBtn" class="btn">Generate</button>
31+
</div>
32+
33+
<div class="password-box">
34+
<input type="text" id="result" readonly>
35+
<button id="copyBtn" class="btn">Copy</button>
36+
</div>
37+
</main>
38+
39+
<script src="password.js"></script>
40+
</body>
41+
</html>

tools/password.js

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const lengthInput = document.getElementById("length");
2+
const lowercaseCb = document.getElementById("lowercase");
3+
const uppercaseCb = document.getElementById("uppercase");
4+
const numbersCb = document.getElementById("numbers");
5+
const symbolsCb = document.getElementById("symbols");
6+
const resultField = document.getElementById("result");
7+
const generateBtn = document.getElementById("generateBtn");
8+
const copyBtn = document.getElementById("copyBtn");
9+
10+
const lowercase = "abcdefghijklmnopqrstuvwxyz";
11+
const uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
12+
const numbers = "0123456789";
13+
const symbols = "!@#$%^&*()_+{}[]<>?/|";
14+
15+
function generatePassword() {
16+
let chars = "";
17+
if (lowercaseCb.checked) chars += lowercase;
18+
if (uppercaseCb.checked) chars += uppercase;
19+
if (numbersCb.checked) chars += numbers;
20+
if (symbolsCb.checked) chars += symbols;
21+
22+
const length = parseInt(lengthInput.value);
23+
if (!chars) {
24+
resultField.value = "Select at least one option!";
25+
return;
26+
}
27+
28+
let password = "";
29+
for (let i = 0; i < length; i++) {
30+
const rand = Math.floor(Math.random() * chars.length);
31+
password += chars[rand];
32+
}
33+
resultField.value = password;
34+
}
35+
36+
generateBtn.addEventListener("click", generatePassword);
37+
38+
copyBtn.addEventListener("click", () => {
39+
if (resultField.value) {
40+
navigator.clipboard.writeText(resultField.value);
41+
alert("Password copied!");
42+
}
43+
});

0 commit comments

Comments
 (0)