简易密码强度检查工具HTML源码第1张插图
  • 首页
  • 每日早报
  • 技术教程
  • 编程语言
    • 网站源码
    • 网页代码
  • 精品软件
    • 手机软件
    • 电脑软件
  • 活动资讯
首页 网页代码 正文

简易密码强度检查工具HTML源码

2024-04-24 17:44 网页代码 阅读 980

本文将详细介绍一款基于HTML、CSS和JavaScript编写的简单密码强度检查工具,已经汉化了,在输入密码的时候会实时显示强度和改变边框颜色。

简易密码强度检查工具HTML源码第2张插图

示例代码

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>密码强度检查</title>
  <link rel="stylesheet" href="./css/style.css">
</head>
<body>
  <div class="box">
    <h2>密码强度<span id="text">检查</span></h2>
    <input type="password" class="passwordInput" placeholder="请输入您的密码">
    <div class="password-strength"></div>
    <div class="password-strength"></div>
    <div class="password-strength"></div>
  </div>

  <script src="./js/script.js"></script>

</body>
</html>

style.css代码

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  font-family: consolas;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: 100vh;
  background-color: #333;
}

.box {
  position: relative;
  width: 300px;
  height: 50px;
}

.box h2 {
  position: absolute;
  font-size: 1.25em;
  top: -40px;
  color: #fff;
  font-weight: 500;
}

.box input {
  position: absolute;
  inset: 2px;
  z-index: 10;
  border: none;
  outline: none;
  padding: 10px 15px;
  background-color: #333;
  font-size: 1em;
  color: #fff;
}

.box .password-strength {
  position: absolute;
  inset: 0;
  background: #111;
  border-radius: 5px;
  z-index: 1;
}

.box .password-strength:nth-child(3) {
  filter: blur(5px);
}
.box .password-strength:nth-child(4) {
  filter: blur(10px);
}

script.js代码

[xcxyzm]wicg[/xcxyzm]

[sv]

const passwordInput = document.querySelector('.passwordInput')
const passwordStrengths = document.querySelectorAll('.password-strength')
const text = document.getElementById('text')

passwordInput.addEventListener('input', function(event) {

    const password = event.target.value
    const strength = Math.min(password.length, 12)
    const degree = strength * 30 // calulate degree value based on password strength

    const gradientColor = strength <= 4 ? '#ff2c1c' : (strength <= 8 ? '#ff9800' : '#12ff12')
    const  strengthText = strength <= 4 ? '弱' : (strength <= 8 ? '中等' : '强')
    passwordStrengths.forEach(bar => {
      bar.style.background = `conic-gradient(${gradientColor} ${degree}deg, #1115 ${degree}deg)`
    })
    text.textContent = strengthText
    text.style.color = gradientColor
})

[/sv]

声明:本站所有文章除特别声明外,均采用CC BY-NC-SA 4.0许可协议。转载请注明来自 乐我知!
网站侧边栏填加个联系信息代码
« 上一篇 2024-04-25
体验阿里云通义灵码AI必得五万份实物
下一篇 » 2024-04-24

搜索

最新文章

  • 秦一鸣综应C
    2025-12-19
  • 【求助】有没有大哥分享下孢子汉化版
    2025-12-19
  • 【手游推荐】暗黑联盟 v1.2 |免广告获得奖励
    2025-12-19
  • 【分享】唐建伟《C4D广告视觉设计案例教程》
    2025-12-19
  • 【端游推荐】水烟水雾 v1.0.3 中文版
    2025-12-19

热门文章

  • TOP1
    【分享】周传基电影视频合集:电影制作秘籍
    6天前 457
  • TOP2
    【分享】【英语语法全程课】零基础适用(全集50讲)【视频】
    6天前 445
  • TOP3
    【端游推荐】地狱之种:全章节 v2024.12.6 中文版 解压
    7天前 149
  • TOP4
    葫芦里有没有什么可以双人玩的游戏
    6天前 77
  • TOP5
    【分享】文旅商家AI自媒体实战宝典,数字化营销策略+流量变现
    6天前 54

本站部分资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站站长删除。

Copyright © 2018-2025 乐我知 皖ICP备19017711号-2

侵权/投诉/邮箱: 8670468@qq.com

sitemap