Password Strength Checker (JavaScript)

I have built a Password Strength Checker with HTML and JavaScript.In the input field, you can enter any password of your choice and click the check button. The program will tell you if your password length is sufficient or not. You can also click the show password/hide password button to view or hide your password after you have checked its strength. The code is as below :
`

Password Strength Detector
<script>
    
    function sh (b){
        if(document.pass.button.value === "Show Password"){
           document.pass.button.value = "Hide Password" ;
           document.pass.password.type="text";
        }else{
            document.pass.button.value = "Show Password";
            document.pass.password.type="password";
        }
    }
    function p (a){
       var x = document.pass.password.value;
        if (x.length == 0){
            alert("Please Enter a valid Password");
        }else if (x.length <= 4) {
            alert("Password Strength : Weak");
        }else if (x.length <=7) {
            alert("Password Strength : Medium");
        }else{
            alert("Password Strength : Strong");
        }
    }
</script>
    
<body>
    <h1 style="text-align: center">Password Strength Checker</h1>
    <hr/>
    <h4>Enter a password in the space provided below and click the check button to check the strength of your password</h4>
    
    <div style="margin: 0 auto; width: 200px;">
    
    <form name="pass">
        Set up a password : <br/><input type="password" name="password" /><br/>
        <input type="button" name="button" value="Show Password" onclick="sh(this)"/><br/>
        <input type="button" name="Check" value="Check" onclick="p(this)" />
    </form>
    
    </div>
</body>
`
1 Like

Great work! Next steps to improve your algorithm could include checking to see if the password is “hard to guess” (whatever that means to you) in addition to checking the password’s length. Also multi-language support down the line would be very impressive!