From 3cfdffb7b40b7254a5bae7a7ffaa58f7ed2bbb3c Mon Sep 17 00:00:00 2001 From: jayesh Date: Wed, 5 Nov 2025 23:44:54 +0530 Subject: [PATCH] Enhanced Password Generator UX: added copy button, password length input, and theme toggle labels --- Password Generator/index.css | 206 ++++++++++++++++++---------------- Password Generator/index.html | 32 ++++-- Password Generator/index.js | 41 ++++--- 3 files changed, 159 insertions(+), 120 deletions(-) diff --git a/Password Generator/index.css b/Password Generator/index.css index b8bbf74..0d22990 100644 --- a/Password Generator/index.css +++ b/Password Generator/index.css @@ -1,136 +1,148 @@ -body{ - box-sizing: border-box; - font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; - background-color: #1F2937; +body { + box-sizing: border-box; + font-family: 'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif; + background-color: #1F2937; } -.container{ - margin-left: 20%; - margin-right: 10%; +.container { + margin-left: 20%; + margin-right: 10%; } -#headline { - color:#10B981; +#headline1 { + margin-top: 2em; + color: aliceblue; + font-weight: 800; + margin-bottom: 0; + font-size: 2.5rem; } -#btn { - background-color: #10B981; - padding:.7em; - color: white; - font-size: medium; - font-weight: 500; - border: none; - margin-bottom: 1em; - margin-top: 1em; - cursor: pointer; - border-radius:.5rem; +#headline2 { + margin-top: 0em; + margin-bottom: 0; + font-size: 2.5em; + color: #55F991; } -hr{ - color: #273549; - position: absolute; - - width: 30rem; +#line { + color: #D5D4D8; } -#PassContainer{ - border: 2px solid; - margin-top: 1.5em; - margin-right: 2em; - padding-bottom: 2.5rem; - width: 17em; - height: 3em; - line-height: normal; - display: block; - border-radius: .5rem; - background-color: #273549; - color:#000000; -} -.Password1{ - color:#55F991; +#btn { + background-color: #10B981; + padding: 0.7em; + color: white; + font-size: medium; + font-weight: 500; + border: none; + margin-bottom: 1em; + margin-top: 1em; + cursor: pointer; + border-radius: 0.5rem; } -.Password2{ - color:#55F991; + +hr { + color: #273549; + position: absolute; + width: 30rem; } -#headline1{ - margin-top: 2em; - color: aliceblue; - font-weight: 800; - margin-bottom: 0; - font-size: 2.5rem; +.password-container { + display: flex; + gap: 1em; + margin-top: 1em; } -#headline2{ - margin-top: 0em; - margin-bottom: 0; - font-size: 2.5em; - color:#55F991; +.password-box { + border: 2px solid; + padding: 0.5em 1em; + border-radius: 0.5rem; + background-color: #273549; + color: #55F991; + display: flex; + align-items: center; + justify-content: space-between; + width: 16em; +} +.copy-btn { + background-color: #10B981; + border: none; + color: white; + padding: 0.3em 0.6em; + border-radius: 0.3rem; + cursor: pointer; + font-size: 0.9em; } -#line{ - color: #D5D4D8; + +.copy-btn:hover { + opacity: 0.85; } -.password-container{ - display: flex; - +.theme-toggle { + margin-top: 1em; + display: flex; + align-items: center; + gap: 0.5em; } -.switch{ - margin-top: 1em; - margin-left:.5em; - position: relative; - display: inline-block; - width: 60px; - height: 34px; +.switch { + position: relative; + display: inline-block; + width: 60px; + height: 34px; } .switch input { - opacity: 0; - width: 0; - height: 0; + opacity: 0; + width: 0; + height: 0; } -.slider{ - position: absolute; - cursor: pointer; - top: 0; - left: 0; - right: 0; - bottom: 0; - background-color: #273549; - -webkit-transition:.4s; - transition: .4s; +.slider { + position: absolute; + cursor: pointer; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: #273549; + transition: 0.4s; } .slider:before { - position: absolute; - content: ""; - height: 26px; - width: 26px; - left: 4px; - bottom: 4px; - background-color: white; - -webkit-transition: .4s; - transition: .4s; + position: absolute; + content: ""; + height: 26px; + width: 26px; + left: 4px; + bottom: 4px; + background-color: white; + transition: 0.4s; } -input:checked + .slider{ - background-color: #10B981; +input:checked + .slider { + background-color: #10B981; } - input:checked + .slider:before { - -webkit-transform: translateX(26px); - -ms-transform: translateX(26px); - transform: translateX(26px); + transform: translateX(26px); } .slider.round { - border-radius: 34px; + border-radius: 34px; +} + +.slider.round:before { + border-radius: 50%; } -.slider.round:before{ - border-radius: 50%; -} \ No newline at end of file +/* Make label text visible in both themes */ +label { + color: #D5D4D8; /* default for dark mode */ + font-weight: 500; +} + +body.light-mode label { + color: #111827; /* darker text for light mode */ +} diff --git a/Password Generator/index.html b/Password Generator/index.html index 4e75e50..86a1880 100644 --- a/Password Generator/index.html +++ b/Password Generator/index.html @@ -11,20 +11,36 @@

Generate a

random password

Never use an insecure password

+ + + + +
+
- +
+ +

+ +
+ + + +
+ +
- - + + - diff --git a/Password Generator/index.js b/Password Generator/index.js index da55d4a..758dab6 100644 --- a/Password Generator/index.js +++ b/Password Generator/index.js @@ -1,28 +1,27 @@ let mode = document.querySelector("#modeChanger"); let headline = document.getElementById("headline1"); +let headline2 = document.getElementById("headline2"); let body = document.querySelector("body"); let line = document.querySelector("#line"); let hr = document.querySelector("hr"); -let headline2 = document.querySelector("#headline2"); mode.addEventListener("change", () => { if (mode.checked) { + body.classList.add("light-mode"); headline.style.color = "#000000"; - body.style.backgroundColor = "#ECFDF5" - line.style.color = "#6B7280" - hr.style.color = "#E8E7E9" - headline2.style.color = "#10B981" - - + body.style.backgroundColor = "#ECFDF5"; + line.style.color = "#6B7280"; + hr.style.color = "#E8E7E9"; + headline2.style.color = "#10B981"; } else { - headline2.style.color = "#55F991" + body.classList.remove("light-mode"); + headline2.style.color = "#55F991"; headline.style.color = "aliceblue"; - body.style.backgroundColor = "#1F2937" - hr.style.color = "#273549" + body.style.backgroundColor = "#1F2937"; + hr.style.color = "#273549"; } }); - const lowercaseChars = "abcdefghijklmnopqrstuvwxyz"; const uppercaseChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; const numberChars = "0123456789"; @@ -40,10 +39,22 @@ const generatePassword = (length) => { }; const displayPassword = () => { - let dPassword1 = document.querySelector(".Password1"); - dPassword1.textContent = generatePassword(13); - let dPassword2 = document.querySelector(".Password2"); - dPassword2.textContent = generatePassword(12); + const length = parseInt(document.getElementById("lengthInput").value) || 12; + document.querySelector(".Password1").textContent = generatePassword(length); + document.querySelector(".Password2").textContent = generatePassword(length); }; document.getElementById("btn").addEventListener("click", displayPassword); + +// Copy functionality +document.querySelectorAll(".copy-btn").forEach((btn) => { + btn.addEventListener("click", () => { + const targetClass = btn.getAttribute("data-target"); + const text = document.querySelector(`.${targetClass}`).textContent; + if (text.trim()) { + navigator.clipboard.writeText(text); + btn.textContent = "Copied!"; + setTimeout(() => (btn.textContent = "Copy"), 1500); + } + }); +});