PHP学院的中学生 2023-03-14 16:17:32 771次浏览 0条回复 0 0 0
<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <title>Password Strength Checker</title>
    <style>
      .weak {
        background-color: red;
      }
      .medium {
        background-color: yellow;
      }
      .strong {
        background-color: green;
      }
    </style>
  </head>
  <body>
    <label for="password">Password:</label>
    <input type="password" id="password" onkeyup="updatePasswordStrength()" />
    <div id="password-strength"></div>
    <script>
      function updatePasswordStrength() {
        var password = document.getElementById("password").value;
        var passwordStrength = checkPasswordStrength(password);
        var passwordStrengthElement = document.getElementById("password-strength");
        passwordStrengthElement.className = passwordStrength;
        passwordStrengthElement.textContent = passwordStrength.toUpperCase();
      }
      
      function checkPasswordStrength(password) {
        var strongRegex = /^(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[!@#$%^&*])/;
        var mediumRegex = /^(?=.*[A-Za-z])(?=.*\d)(?=.*[!@#$%^&*])/;
        if (strongRegex.test(password)) {
          return "strong";
        } else if (mediumRegex.test(password)) {
          return "medium";
        } else {
          return "weak";
        }
      }
    </script>
  </body>
</html>
    没有找到数据。
您需要登录后才可以回复。登录 | 立即注册