Password Strength Algorithm:
Password Length:
5 Points: Less than 4 characters
10 Points: 5 to 7 characters
25 Points: 8 or more
Letters:
0 Points: No letters
10 Points: Letters are all lower case
20 Points: Letters are upper case and lower case
Numbers:
0 Points: No numbers
10 Points: 1 number
20 Points: 3 or more numbers
Characters:
0 Points: No characters
10 Points: 1 character
25 Points: More than 1 character
Bonus:
2 Points: Letters and numbers
3 Points: Letters, numbers, and characters
5 Points: Mixed case letters, numbers, and characters
Password Text Range:
>= 90: Very Secure
>= 80: Secure
>= 70: Very Strong
>= 60: Strong
>= 50: Average
>= 25: Weak
>= 0: Very Weak
Cài đặt Chuyển thành true hoặc false, nếu bạn muốn thay đổi những gì được kiểm tra trong mật khẩu
var m_strUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
var m_strLowerCase = "abcdefghijklmnopqrstuvwxyz";
var m_strNumber = "0123456789";
var m_strCharacters = "!@#$%^&*?_~"
Check password
function checkPassword(strPassword)
{
var nScore = 0;
if (strPassword.length < 5)
{
nScore += 5;
}
else if (strPassword.length > 4 && strPassword.length < 8)
{
nScore += 10;
}
else if (strPassword.length > 7)
{
nScore += 25;
}
var nUpperCount = countContain(strPassword, m_strUpperCase);
var nLowerCount = countContain(strPassword, m_strLowerCase);
var nLowerUpperCount = nUpperCount + nLowerCount;
if (nUpperCount == 0 && nLowerCount != 0)
{
nScore += 10;
}
else if (nUpperCount != 0 && nLowerCount != 0)
{
nScore += 20;
}
var nNumberCount = countContain(strPassword, m_strNumber);
if (nNumberCount == 1)
{
nScore += 10;
}
if (nNumberCount >= 3)
{
nScore += 20;
}
var nCharacterCount = countContain(strPassword, m_strCharacters);
if (nCharacterCount == 1)
{
nScore += 10;
}
if (nCharacterCount > 1)
{
nScore += 25;
}
if (nNumberCount != 0 && nLowerUpperCount != 0)
{
nScore += 2;
}
if (nNumberCount != 0 && nLowerUpperCount != 0 && nCharacterCount != 0)
{
nScore += 3;
}
if (nNumberCount != 0 && nUpperCount != 0 && nLowerCount != 0 && nCharacterCount != 0)
{
nScore += 5;
}
return nScore;
}
function runPassword(strPassword, strFieldID)
{
var nScore = checkPassword(strPassword);
var ctlBar = document.getElementById(strFieldID + "_bar");
var ctlText = document.getElementById(strFieldID + "_text");
if (!ctlBar || !ctlText)
return;
ctlBar.style.width = (nScore*1.25>100)?100:nScore*1.25 + "%";
if (nScore >= 80)
{
var strText = "Very Strong";
var strColor = "#008000";
}
else if (nScore >= 60)
{
var strText = "Strong";
var strColor = "#006000";
}
else if (nScore >= 40)
{
var strText = "Average";
var strColor = "#e3cb00";
}
else if (nScore >= 20)
{
var strText = "Weak";
var strColor = "#Fe3d1a";
}
else
{
var strText = "Very Weak";
var strColor = "#e71a1a";
}
if(strPassword.length == 0)
{
ctlBar.style.backgroundColor = "";
ctlText.innerHTML = "";
}
else
{
ctlBar.style.backgroundColor = strColor;
ctlText.innerHTML = strText;
}
}
function countContain(strPassword, strCheck)
{
var nCount = 0;
for (i = 0; i < strPassword.length; i++)
{
if (strCheck.indexOf(strPassword.charAt(i)) > -1)
{
nCount++;
}
}
return nCount;
}
Bạn có thể tùy chỉnh bởi chính mình theo yêu cầu của bạn.