-
-
Save darioalbanesi/8e9976a791bd9bc51aa6 to your computer and use it in GitHub Desktop.
_Pupo - Password Strength Checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.password-strength { | |
label { float:left; margin-right: 15px; } | |
#passstrength { | |
height: 10px; | |
width:310px; | |
display: block; | |
float:left; | |
margin-top:6px; | |
background-color: grey; | |
} | |
.ok { background-color: green !important; background-size: 100%; } | |
.medium { background-image: linear-gradient(left, orange, orange 50%, transparent 50%, transparent 100%); } | |
.weak { background-image: linear-gradient(left, red, red 10%, transparent 10%, transparent 100%); } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<form action="." role="form"> | |
<fieldset> | |
<div class="form-group"> | |
<label for="pass">Password *</label> | |
<input id="pass" type="password" class="form-control" /> | |
</div> | |
<div class="password-strength"> | |
<label>Password strength</label> | |
<div id="passstrength"></div> | |
</div> | |
</fieldset> | |
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('#pass').keyup(function(e) { | |
var strongRegex = new RegExp("^(?=.{8,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g"); | |
var mediumRegex = new RegExp("^(?=.{7,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g"); | |
var enoughRegex = new RegExp("(?=.{6,}).*", "g"); | |
if (false == enoughRegex.test($(this).val())) { | |
//$('#passstrength').html('More Characters'); | |
$('#passstrength').removeClass(); | |
} else if (strongRegex.test($(this).val())) { | |
//$('#passstrength').html('Strong!'); | |
$('#passstrength').removeClass(); | |
$('#passstrength').addClass('ok'); | |
} else if (mediumRegex.test($(this).val())) { | |
//$('#passstrength').html('Medium!'); | |
$('#passstrength').removeClass(); | |
$('#passstrength').addClass('medium'); | |
} else { | |
//$('#passstrength').html('Weak!'); | |
$('#passstrength').removeClass(); | |
$('#passstrength').addClass('weak'); | |
} | |
return true; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment