Simple password strength meter using jquery

 Html file code for password meter


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
#passwordStrength
{
    height:10px;
    display:block;
    float:left;
}
.strength0
{
    width:250px;
    background:#cccccc;
}
.strength1
{
    width:50px;
    background:#FF0000;
}

.strength2
{
    width:100px;  
    background:#CCCC33;
}
.strength3
{
    width:250px;  
    background:#00FF66;
}
</style>
<script type="text/javascript" src="
http://code.jquery.com/jquery-latest.js
"></script>
<script type="text/javascript">
    $(document).ready(function()
        {
            $("#loader").hide();
            $("#password").keyup(function()
                {
                     $("#loader").show().fadeOut(2000); 
                  
                    var password_length = $("#password").val().length;          
                        if (password_length == 0)
                        {
                            $("#passwordStrength").removeClass().addClass("strength0");
                            $("#message1").html("");
                        }
                        else if (password_length <= 6)
                        {
                            $("#passwordStrength").removeClass().addClass("strength1");
                            $("#message1").html("Very Short");
                        }
                    else if(password_length > 6 &&  password_length <= 12)
                        {
                            $("#passwordStrength").removeClass().addClass("strength2");
                            $("#message1").html("good");
                        }
                    else if(password_length > 12)
                        {
                            $("#passwordStrength").removeClass().addClass("strength3");
                            $("#message1").html("vary good");
                        }          
                });
        });      
</script>
</head>
<body>

<input name="password" type="text" id="password"/><div id="message1"> </div>
<p>     <div id="passwordStrength" class="strength0" > </div></p>
<div id="loader">Loading.........</div>
</div>
</body>
</html>

No comments:

Post a Comment