This repository was archived by the owner on Aug 21, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
59 lines (50 loc) · 2.18 KB
/
Copy pathscript.js
File metadata and controls
59 lines (50 loc) · 2.18 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
const passwordDisplay = document.getElementById("password");
const lengthInput = document.getElementById("length");
const lengthValue = document.getElementById("lengthValue");
const strengthDisplay = document.getElementById("strength");
const uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const lowercaseChars = "abcdefghijklmnopqrstuvwxyz";
const numberChars = "0123456789";
const symbolChars = "!@#$%^&*()-_=+[]{}|;:,.<>?/";
function generatePassword() {
const length = parseInt(lengthInput.value);
const includeUppercase = document.getElementById("uppercase").checked;
const includeLowercase = document.getElementById("lowercase").checked;
const includeNumbers = document.getElementById("numbers").checked;
const includeSymbols = document.getElementById("symbols").checked;
let charPool = "";
if (includeUppercase) charPool += uppercaseChars;
if (includeLowercase) charPool += lowercaseChars;
if (includeNumbers) charPool += numberChars;
if (includeSymbols) charPool += symbolChars;
if (charPool === "") {
passwordDisplay.textContent = "Please select at least one option";
strengthDisplay.textContent = "Strength: -";
return;
}
let password = "";
for (let i = 0; i < length; i++) {
const randomIndex = Math.floor(Math.random() * charPool.length);
password += charPool[randomIndex];
}
passwordDisplay.textContent = password;
evaluateStrength(password);
}
function evaluateStrength(password) {
const length = password.length;
let strength = "Weak";
if (length >= 12 && /[A-Z]/.test(password) && /[a-z]/.test(password) && /\d/.test(password) && /[^A-Za-z0-9]/.test(password)) {
strength = "Strong";
} else if (length >= 8) {
strength = "Medium";
}
strengthDisplay.textContent = `Strength: ${strength}`;
}
function copyToClipboard() {
const text = passwordDisplay.textContent;
if (!text || text === "Click Generate" || text === "Please select at least one option") return;
navigator.clipboard.writeText(text).then(() => alert("Password copied to clipboard!"));
}
lengthInput.addEventListener("input", () => {
lengthValue.textContent = lengthInput.value;
});