jQuery.strength = function( element, password ) {
var desc = [{'width':'0px'}, {'width':'20%'}, {'width':'40%'}, {'width':'60%'}, {'width':'80%'}, {'width':'100%'}];
var descClass = ['', 'progress-bar-danger', 'progress-bar-danger', 'progress-bar-warning', 'progress-bar-success', 'progress-bar-success'];
var score = 0;
if(password.length > 6){
score++;
}
if ((password.match(/[a-z]/)) && (password.match(/[A-Z]/))){
score++;
}
if(password.match(/\d+/)){
score++;
}
if(password.match(/.[!,@,#,$,%,^,&,*,?,_,~,-,(,)]/)){
score++;
}
if (password.length > 10){
score++;
}
element.removeClass( descClass[score-1] ).addClass( descClass[score] ).css( desc[score] );
};
jQuery(function() {
jQuery("#pwd").keyup(function() {
jQuery.strength(jQuery("#progress-bar"), jQuery(this).val());
});
});
form {
max-width: 400px;
padding: 2em;
border:1px dashed #ddd
}
#pwd{
border-radius:50px;
padding: 10px 20px;
border:2px solid #999;
}
*:focus {
outline-style: none;
}
input {
display: block;
width: 100%;
box-sizing: border-box;
padding: 6px;
border: 1px solid #ddd;
}
#progressBar {
height: 20px;
width: 100%;
margin-top: 0.6em;
border-radius:50px;
border:2px solid #ddd
}
#progress-bar {
width: 0%;
height: 100%;
transition: width 500ms linear;
border-radius:50px;
box-shadow:0px 1px 5px #555
}
.progress-bar-danger {
background: #d00;
}
.progress-bar-warning {
background: #f50;
}
.progress-bar-success {
background: #080;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<h3> Password Strength Using JAVASCRIPT.</h3>
<form name="passwordStrengthBox">
<div class="passBox">
<input type="text" id="pwd" autocomplete="off" placeholder="Enter Passwords">
<div id="progressBar">
<div id="progress-bar"></div>
</div>
</div>
</form>