JavaScript password strength checker

preview_player
Показать описание
Link for all dot net and sql server video tutorial playlists

Link for slides, code samples and text version of the video

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

In this video we will discuss how to implement a simple password strength checker using JavaScript.

As we type the password in the password TextBox, the strength of the password should be displayed in a label control.

The password strength is determined based on the following scoring criteria.

If the password contain atleast 8 characters - 20 Points
If the password contain atleast 1 lowercase letter - 20 Points
If the password contain atleast 1 uppercase letter - 20 Points
If the password contain atleast 1 number - 20 Points
If the password contain atleast 1 special character - 20 Points

The password strength is determined using the following scale.

Password Score - Password Strength
]= 100 - Strong
]= 80 - Medium
]= 60 - Weak
[ 60 - Very Weak

Example :
[asp:TextBox ID="TextBox1" runat="server" TextMode="Password"
onkeyup="checkPasswordStrength()"]
[/asp:TextBox]
[asp:Label ID="lblMessage" runat="server"][/asp:Label]
[script type="text/javascript"]
function checkPasswordStrength()
{
var specialCharacters = "!£$%^&*_@#~?";
var passwordScore = 0;

// Contains special characters
{
{
passwordScore += 20;
break;
}
}

// Contains numbers
if (/\d/.test(password))
passwordScore += 20;

// Contains lower case letter
if (/[a-z]/.test(password))
passwordScore += 20;

// Contains upper case letter
if (/[A-Z]/.test(password))
passwordScore += 20;

passwordScore += 20;

var strength = "";
var backgroundColor = "red";

if (passwordScore ]= 100)
{
strength = "Strong";
backgroundColor = "green";
}
else if (passwordScore ]= 80)
{
strength = "Medium";
backgroundColor = "gray";
}
else if (passwordScore ]= 60)
{
strength = "Weak";
backgroundColor = "maroon";
}
else
{
strength = "Very Weak";
backgroundColor = "red";
}

}
[/script]
Рекомендации по теме
Комментарии
Автор

Hi Kudvenkat,

I really like your videos and the way explain things in a very simple way.
Can you please make videos on Serialization, DeSerisalization, Threading in C# .Net Thank you

gaganvirk
Автор

Hi Sir,
I really like your videos and I learn from your videos they are very useful.
Would you please upload a video on payment integration in asp.net ?
Thank you.

faizanqureshi
Автор

good tutorial as usual, but there's one problem with this code; what if someone type more than one special character.as it's a for loop it will increment the strength by 20 and you can get 100 pts for typing 5 special chars

mohamedbakir
Автор

Could we use ascii code?, because all special chars come from 32-40 range, we also know the range of small and caps alphabets, string.charCodeAt(i) returns the ascii, so this way we dont need to hardcode the special characters... also dont need to calculate the strength score seperately...

amland
Автор

Hi kudvenkat, I cannot get this to work.

First I don't think onkeyup is valid in asp:textbox so I added to page load: TextBoxPassword1.Attributes.Add("onkeyup", "passwordstrength();");

Now I think this doesn't return any value:

var passwordTextBox =
var password = passwordTextBox.value;

If I add:
alert("TESTING");
after
var passwordTextBox =
... it fires OK
After var password =
... it does not fire.

Any ideas on the problem?

IainBrogden
visit shbcf.ru