开发者们大家好!我很高兴向大家展示我的最新项目:密码生成器。该工具旨在帮助您轻松创建安全且随机的密码。无论您的在线帐户需要强密码还是想要练习 JavaScript 技能,此密码生成器都是您工具包的绝佳补充。
密码生成器是一个基于网络的应用程序,允许用户使用各种配置生成密码。您可以自定义密码长度并包含或排除特定字符类型,例如小写字母、大写字母、数字和符号。该项目展示了如何使用 JavaScript 构建动态密码生成器,并结合使用 HTML 和 CSS 构建的干净且用户友好的界面。
以下是项目结构的概述:
Password-Generator/ ├── index.html ├── style.css └── script.js
要开始该项目,请按照以下步骤操作:
克隆存储库:
git clone https://github.com/abhishekgurjar-in/Password-Generator.git
打开项目目录:
cd Password-Generator
运行项目:
index.html 文件定义了密码生成器的结构,包括输入字段、控件和显示区域。这是一个片段:
8b05045a5be5764f313ed5b9168a17e6 49099650ebdc5f3125501fa170048923 93f0f5c25f18dab9d176bd4f6de5d30e 7c8d9f814bcad6a1d7abe4eda5f773e5 acd8feeb3a0ea7477b979779de32785a 26faf3d1af674280d03ba217d87e9421 af75c476cdb7e6c074ca6da9b40841de d8503bdefe6992dd59b651156c1a80eb 90392ec4442ad9ff612213ec639da4832cacc6d41bbb37262a98f745aa00fbf0 b2386ffb911b14667cb8f0f91ea547a7Password Generator6e916e0f7d1e588d4f442bf645aedb2f 9c3bca370b5104690d9ef395f2c5f8d1 6c04bd5ca3fcae76e30b72ad730ca86d 4883ec0eb33c31828b7c767c806e14c7 4a249f0d628e2318394fd9b75b4636b1Password Generator473f0a7621bec819994bb5020d29372a 34a25c77a2e9da798136e01b207e55d8 9f296658183c8dc217a6dd649074b65b b447d4e20918108d1f227b35d3f83b0ccontent_copy54bdf357c58b8a65c66d7c19c8e4d114 16b28748ea4df4d9c2150843fecfba68 2099bb55d2af935eea656fe56e182519 39bbc163833ae4e036fa5108a4263823 e388a4556c0f65e1904146cc1a846beePassword Length94b3e26ee717c64999d7867364b1b4a3 98f5e630a88a7d7159f08c0a14a2752d54bdf357c58b8a65c66d7c19c8e4d114 16b28748ea4df4d9c2150843fecfba68 39bbc163833ae4e036fa5108a4263823 e7dc9bb71ade5e1b977b4fc7169140c4Include Lowercase Letters (a-z)8c1ecd4bb896b2264e0711597d40766c a8b444646b004d6a82c0efc74a0796e3 16b28748ea4df4d9c2150843fecfba68 39bbc163833ae4e036fa5108a4263823 dcc61bab82ce65042ff81e61d412a812Include Uppercase Letters (A-Z)8c1ecd4bb896b2264e0711597d40766c 86ca2e498f4feae7bb126ce425dec34f 16b28748ea4df4d9c2150843fecfba68 39bbc163833ae4e036fa5108a4263823 0128196305b1d83f036472d48485215bInclude Numbers (0-9)8c1ecd4bb896b2264e0711597d40766c b9a60207358383794656d179ccc43b2c 16b28748ea4df4d9c2150843fecfba68 39bbc163833ae4e036fa5108a4263823 74ac59835abb23d9c05434e220125466Include Symbols (@-*)8c1ecd4bb896b2264e0711597d40766c 1c9eb7b8553dbb5287a55dc1961edc08 16b28748ea4df4d9c2150843fecfba68 1fd90c1118fb6157c85d8e0f0e7a7221 Generate Password 65281c5ac262bf6d81768915a4a77ac0 16b28748ea4df4d9c2150843fecfba68 ffd6ba4147bda351239915f463e46e38 e388a4556c0f65e1904146cc1a846beeMade with ❤️ by Abhishek Gurjar94b3e26ee717c64999d7867364b1b4a3 16b28748ea4df4d9c2150843fecfba68 36cc49f0c466276486e50c850b7e4956 73a6ac4ed44ffec12cee46588e518a5e
style.css 文件设置密码生成器的样式,使其具有视觉吸引力和响应能力。以下是一些关键样式:
* { margin: 0; padding: 0; box-sizing: border-box; font-family: sans-serif; } body { max-width: 100vw; min-height: 100vh; display: flex; justify-content: center; align-items: center; background: #000; color: #fff; font-weight: 600; flex-direction: column; } .container { border: 0.5px solid #fff; border-radius: 10px; padding: 28px 32px; display: flex; flex-direction: column; background: transparent; box-shadow: 8px 8px 4px #909090, 8px 8px 0px #575757; } .container h1 { font-size: 1.4rem; margin-block: 8px; } .inputBox { position: relative; } .inputBox span { position: absolute; top: 16px; right: 6px; color: #000; font-size: 28px; cursor: pointer; z-index: 2; } .passBox { background-color: #fff; border: none; outline: none; padding: 10px; width: 300px; border-radius: 4px; font-size: 20px; margin-block: 8px; text-overflow: ellipsis; } .row { display: flex; margin-block: 8px; } .row p, .row label { flex-basis: 100%; font-size: 18px; } .row input[type="checkbox"] { width: 20px; height: 20px; } .genBtn { border: none; outline: none; background-color: #2c619e; padding: 12px 24px; color: #fff; font-size: 18px; margin-block: 8px; font-weight: 700; cursor: pointer; border-radius: 4px; } .genBtn:hover { background-color: #0066ff; } .footer { color: white; margin-top: 150px; text-align: center; } .footer p { font-size: 16px; font-weight: 200; }
script.js 文件包含生成密码、管理用户交互以及将密码复制到剪贴板的逻辑。这是一个片段:
let inputSlider = document.getElementById("inputSlider"); let sliderValue = document.getElementById("sliderValue"); let passBox = document.getElementById("passBox"); let lowercase = document.getElementById("lowercase"); let uppercase = document.getElementById("uppercase"); let numbers = document.getElementById("numbers"); let symbols = document.getElementById("symbols"); let genBtn = document.getElementById("genBtn"); let copyIcon = document.getElementById("copyIcon"); // Showing input slider value sliderValue.textContent = inputSlider.value; inputSlider.addEventListener("input", () => { sliderValue.textContent = inputSlider.value; }); genBtn.addEventListener("click", () => { passBox.value = generatePassword(); }); let lowerChars = "abcdefghijklmnopqrstuvwxyz"; let upperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; let allNumbers = "0123456789"; let allSymbols = "~!@#$%^&*"; // Function to generate Password function generatePassword() { let genPassword = ""; let allChars = ""; allChars += lowercase.checked ? lowerChars : ""; allChars += uppercase.checked ? upperChars : ""; allChars += numbers.checked ? allNumbers : ""; allChars += symbols.checked ? allSymbols : ""; if (allChars === "") { return genPassword; } let i = 1; while (i 4c18bbaca350f2b916a43e11d91f001a { if (passBox.value !== "") { navigator.clipboard.writeText(passBox.value); copyIcon.innerText = "check"; copyIcon.title = "Password Copied"; setTimeout(() => { copyIcon.innerHTML = "content_copy"; copy Icon.title = ""; }, 3000); } });
您可以在此处查看密码生成器项目的现场演示。
创建密码生成器是一个令人愉快的项目,它使我能够应用我的前端开发技能。该工具对于生成强密码非常有用,并且可以成为您的 Web 开发项目的重要补充。我希望你发现它和我一样有帮助。快乐编码!
这个项目是我增强 JavaScript 技能和创建实用网络工具之旅的一部分。
以上是建立一个密码生成器网站的详细内容。更多信息请关注PHP中文网其他相关文章!