Password checker using html css javascript

<!DOCTYPE html>

<html lang="en">

<head>

  <meta charset="UTF-8">

  <meta name="viewport" content="width=device-width, initial-scale=1.0">

  <title>Password Checker</title>

  <style>

    body {

      font-family: Arial, sans-serif;

    }


    .container {

      max-width: 400px;

      margin: 50px auto;

      padding: 30px;

      border: 2px solid #ccc;

      border-radius: 10px;

    }


    input[type="password"] {

      width: 100%;

      padding: 10px;

      margin-bottom: 10px;

      border: 2px solid #ccc;

      border-radius: 5px;

      transition: border-color 0.3s ease;

    }


    input[type="password"].weak {

      border-color: #ff4d4d; /* red */

    }


    input[type="password"].medium {

      border-color: #ffa500; /* orange */

    }


    input[type="password"].strong {

      border-color: #00cc66; /* green */

    }

  </style>

</head>

<body>

  <div class="container">

    <h2>Password Strength Checker</h2>

    <input type="password" id="password" placeholder="Enter your password" oninput="checkStrength()">

  </div>


  <script>

    function checkStrength() {

      var password = document.getElementById("password").value;

      var passwordInput = document.getElementById("password");


      var strength = 0;


      if (password.length >= 8) {

        strength += 1;

      }

      if (password.match(/[a-z]+/)) {

        strength += 1;

      }

      if (password.match(/[A-Z]+/)) {

        strength += 1;

      }

      if (password.match(/[0-9]+/)) {

        strength += 1;

      }

      if (password.match(/[!@#$%^&*()_+{}|:"<>?]+/)) {

        strength += 1;

      }


      if (strength == 0) {

        passwordInput.className = "weak";

      } else if (strength <= 2) {

        passwordInput.className = "medium";

      } else {

        passwordInput.className = "strong";

      }

    }

  </script>

</body>

</html>


Comments