-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
48 lines (39 loc) · 1.53 KB
/
Copy pathscript.js
File metadata and controls
48 lines (39 loc) · 1.53 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
const passwordInput = document.getElementById("password");
const feedback = document.getElementById("feedback");
const strengthBar = document.getElementById("strength-bar");
const voiceToggle = document.getElementById("voiceToggle");
let speakTimeout;
passwordInput.addEventListener("input", () => {
const pwd = passwordInput.value;
const strength = analyzePassword(pwd);
updateUI(strength);
});
function analyzePassword(pwd) {
let poolSize = 0;
if (/[a-z]/.test(pwd)) poolSize += 26;
if (/[A-Z]/.test(pwd)) poolSize += 26;
if (/[0-9]/.test(pwd)) poolSize += 10;
if (/[^A-Za-z0-9]/.test(pwd)) poolSize += 32;
const entropy = pwd.length * Math.log2(poolSize || 1);
if (entropy < 28) return { level: "Weak", color: "red", width: "25%" };
if (entropy < 36) return { level: "Medium", color: "orange", width: "50%" };
if (entropy < 60) return { level: "Strong", color: "green", width: "75%" };
return { level: "Very Strong", color: "blue", width: "100%" };
}
function updateUI(strength) {
const message = `Strength: ${strength.level}`;
feedback.textContent = message;
strengthBar.style.width = strength.width;
strengthBar.style.backgroundColor = strength.color;
clearTimeout(speakTimeout);
if (voiceToggle.checked) {
speakTimeout = setTimeout(() => speak(message), 300);
}
}
function speak(text) {
const utterance = new SpeechSynthesisUtterance(text);
utterance.lang = "en-US";
utterance.rate = 1;
speechSynthesis.cancel();
speechSynthesis.speak(utterance);
}