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

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

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

本文将详细介绍一款基于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

搜索

最新文章

  • 【手游推荐】:冰雪幸存者基地 免广告
    2025-12-04
  • 【分享】闫帅奇-男性生活化减脂-2025付费课程
    2025-12-04
  • 【手游推荐】侠盗猎车手X:夜之城(钞票不减反增)
    2025-12-04
  • 【端游推荐】谁在门外_v1.0.9 解压即玩
    2025-12-04
  • 【端游推荐】维拉克塔尔
    2025-12-04

热门文章

  • TOP1
    【新机盘点】超大杯旗舰新机;7000mAh旗舰手机
    7天前 261
  • TOP2
    【端游推荐】吸血鬼猎人 v1.4.0 中文版 解压即玩
    6天前 103
  • TOP3
    【端游推荐】消逝的光芒:困兽 1.4.0 豪华中文 单机+联机版
    7天前 100
  • TOP4
    【新机盘点】6.3英寸小屏手机;7000mAh旗舰新机
    7天前 86
  • TOP5
    【玩机话题】喜欢开保护电池的iPhone用户天塌了!
    7天前 72

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

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

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

sitemap