CodeClerks

How to Check Password Strength using Regular Expression



Write the reason you're deleting this FAQ

How to Check Password Strength using Regular Expression

In one of my earlier tutorial, How to Create Strong Passwords, I discussed about creating strong password. But that was one side of the coin! I mean, that tutorial was for internet users who wants to keep there account secure. But what is your responsibility as a webmaster? You have make sure that when user is registering your site you inform user about his/her password quality. You can provide dynamic feedback (as user types) to user on a webpage using javascript! In this tutorial, I'll share the javascript which you need to embed in your webpage.

There are pros and cons of using javascript to test password strength. One of the most important pro of using javascript, is that, it will not overload your server with request for checking password strength. Another advantage you are saving user's time & bandwidth. As it will not allow user to submit form, until he/she has input string password. Disadvantage of using javascript is user can always disable javascript through browser settings, so the trick of using javascript might fail! You can overcome this problem by forcing user to enable javascript or do a re-check at server for password strength. It will also help you in doing double check of password strength.

In this tutorial, we will be using regular expression to check password strength. Please look into f0llowing code,


<html>
<head>
<script language="javascript">

function passwordStrength(pwd){
var msg = "Your Password is too weak!";
var pwdPoint = pwd.length;
var pwdIndicator = document.getElementById('pwdIndicator');

var lowerCaseCheck = new RegExp("[a-z]"); //checking for existence of lower case letter
var upperCaseCheck = new RegExp("[A-Z]"); //checking for existence of upper case letter
var numberExistenceCheck = new RegExp("[0-9]"); //checking for existence of number
var symbolExistenceCheck = new RegExp("\\W"); //checking for existence of symbol

if(pwdPoint > 7)
{
pwdPoint = 0;
if(lowerCaseCheck.test(pwd)) { pwdPoint += 4; }
if(upperCaseCheck.test(pwd)) { pwdPoint += 4; }
if(numberExistenceCheck.test(pwd)) { pwdPoint += 4; }
if(symbolExistenceCheck.test(pwd)) { pwdPoint += 4; }

if(pwdPoint>=16) { msg = "Your Password is Strong!"; }
else if(pwdPoint>=12) { msg = "Your Password is Normal!"; }
else if(pwdPoint>=8) { msg = "Your Password is weak!"; }
else if(pwdPoint>=4) { msg = "Your Password is too weak!"; }
else { msg = "Your Password is too weak!"; }
}
pwdIndicator.innerHTML = msg ;
}
</script>
</head>

<body>
<input type="text" name="pwd" id="pwd" size="20" onkeyup="return passwordStrength(this.value);" />
<span id="pwdIndicator" name="pwdIndicator"><b>Password Check!</b></span>
</body>
</html>

https://codeclerks.com/forum/attachments/.337/
https://codeclerks.com/forum/attachments/.334/
https://codeclerks.com/forum/attachments/.335/ Above code checks for password strength and show feedback on screen as user types. It does it with help of "onkeyup" attribute of input tag. You need to write another function which is called on submit button, were you check if password is strong or not using above mentioned function. If password isn't strong then you shouldn't allow user to submit form or based on your requirement you can lower the bar of security and customize above javascript code for a user to register. I'll comeback with new tutorial ASAP. So, stay tuned to SEOClerks! How to Check Password Strength using Regular Expression

Comments

Please login or sign up to leave a comment

Join
tionna
I have had issues with passwords in the past so I will take your advice here and learn from it.



Are you sure you want to delete this post?

angie828
Great job Shek. Nice work once again.



Are you sure you want to delete this post?

evie
Looks complicated in a way but thanks.



Are you sure you want to delete this post?

ralph101
Shek you are a tutorial God!



Are you sure you want to delete this post?

loulou
Wonderful job on this. Will have to check it out.



Are you sure you want to delete this post?

twilight
Nice posting, will be sure to utilize this one.



Are you sure you want to delete this post?

Miken34
Wonderful work on these. Will you be adding more posts soon?



Are you sure you want to delete this post?

ultimate
For passwords, I used to make new passwords and keep track of them manually until I me http://go.yoar.in/ZakdW
It now feels like a breeze using this Google Chrome Extension.



Are you sure you want to delete this post?

haleystar
tank you



Are you sure you want to delete this post?