function testPassword(passwd)
{
var intScore = 0
var strVerdict = ""
// PASSWORD LENGTH
if (passwd.length>7) // length more than 7
{
intScore = (intScore+3)
}
else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
{
intScore = (intScore+6)
}
else if (passwd.length>15) // length 16 or more
{
intScore = (intScore+9)
}
// LETTERS (Not exactly implemented as dictacted above because of my limited understanding of Regex)
if (passwd.match(/[a-z]/)) // [verified] at least one lower case letter
{
intScore = (intScore+1)
}
if (passwd.match(/[A-Z]/)) // [verified] at least one upper case letter
{
intScore = (intScore+1)
}
// NUMBERS
if (passwd.match(/\d+/)) // [verified] at least one number
{
intScore = (intScore+1)
}
if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) // [verified] at least three numbers
{
intScore = (intScore+3)
}
// COMBOS
if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) // [verified] both upper and lower case
{
intScore = (intScore+1)
}
if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
{
intScore = (intScore+1)
}
if(intScore <= 4)
{
strVerdict = '
' + PWSAFETY_LOW + '
'
}
else if (intScore > 4 && intScore <= 7)
{
strVerdict = '' + PWSAFETY_MIDDLE + '
'
}
else if (intScore > 7 && intScore <= 13)
{
strVerdict = '' + PWSAFETY_HIGH + '
'
}
else if (intScore > 13 && intScore <= 17)
{
strVerdict = '' + PWSAFETY_VERYHIGH + '
'
}
else
{
strVerdict = '' + PWSAFETY_PERFECT + '
'
}
return strVerdict;
}
function checklength(text)
{
if(text.length > 50)
{
var splitPos = text.indexOf(" ", (text.length/2));
var part1 = text.substr(0, splitPos);
var part2 = text.substr(splitPos, text.length);
var newtext = part1+'
'+part2;
return newtext;
}
else
return text;
}
var passwordMeter = {
isValid: function (passwd1, passwdCmt1, passwd2, passwdCmt2)
{
this.p1 = document.getElementById(passwd1);
this.c1 = document.getElementById(passwdCmt1);
this.c1c = this.c1;
this.p2 = document.getElementById(passwd2);
this.c2 = document.getElementById(passwdCmt2);
this.imgOK = '
';
this.imgFAIL = '
';
this.msgtrue = MSG_PWCORRECT;
var valid = true;
var msg = '';
var pw = document.getElementById(passwd1).value
var pwsafety = '
' + testPassword(pw);
if (this.c1.getElementsByTagName('span')[0])
this.c1c = this.c1.getElementsByTagName('span')[0];
if (this.p1.value == '')
{
msg = '';
valid = false;
}
else if (this.p1.value.length < 6)
{
msg = MSG_PWLENGHT;
valid = false;
}
else if (this.p1.value.length > 19)
{
msg = MSG_PWTOLONG;
valid = false;
}
else
{
if (!this.p1.value.match(/[0-9]+/))
{
msg += MSG_PWDIGIT+'
';
valid = false;
}
if (!this.p1.value.match(/[a-z]/))
{
msg += MSG_PWLOWERCASE+'
';
valid = false;
}
if (!this.p1.value.match(/[A-Z]/))
{
msg += MSG_PWUPPERCASE+'
';
valid = false;
}
if (this.p1.value.match(/[^A-Za-z0-9]/))
{
msg += MSG_PWSPECIAL+'
';
valid = false;
}
msg = MSG_PWATTRIBUTE+'
'+msg;
}
if (valid)
{
this.c1c.innerHTML = this.imgOK + this.msgtrue + pwsafety;
this.c1.style.display = 'block';
}
else if (msg != '')
{
this.c1c.innerHTML = this.imgFAIL + msg;
this.c1.style.display = 'block';
}
else
{
if (this.c1c.innerHTML = '');
this.c1.style.display = 'none';
}
if (this.p2)
passwordMeter.equals();
return valid;
},
equals: function ()
{
if (this.p1.value != '' && this.p1.value == this.p2.value)
{
this.c2.innerHTML = this.imgOK;
return true;
}
else
{
this.c2.innerHTML = (this.p2.value != '') ? this.imgFAIL : '';
return false;
}
},
blur: function()
{
if (this.c1c.innerHTML = this.imgOK + this.msgtrue)
{
this.c1.style.display = 'none';
}
else
{
this.c1c.innerHTML = this.imgFAIL + msg;
this.c1.style.display = 'block';
}
}
};
var userMeter = {
isValid: function (username, usernameCmt)
{
this.el_username = document.getElementById(username);
this.el_usernameCmt = document.getElementById(usernameCmt);
this.imgOK = '
';
this.imgFAIL = '
';
var divbox_begin = '';
var divbox_end = '';
var valid = true;
var msg = '';
var msgtrue = MSG_USERCORRECT;
if (this.el_username.value == '')
{
msg = MSG_USERINFO;
valid = false;
}
else if (this.el_username.value.length < 4)
{
msg = MSG_USERLENGHT;
valid = false;
}
else if (this.el_username.value.length > 16)
{
msg = MSG_USERINFO;
valid = false;
}
else
{
if (this.el_username.value.match(/[^A-Za-z0-9]/))
{
msg += MSG_USERSPECIAL+'
';
valid = false;
}
msg = MSG_USERATTRIBUTE+'
'+msg;
}
if (valid)
{
this.el_usernameCmt.innerHTML = divbox_begin + this.imgOK + msgtrue + divbox_end;
}
else if (msg != '')
{
this.el_usernameCmt.innerHTML = divbox_begin + (msg == MSG_USERINFO ? msg : this.imgFAIL + msg) + divbox_end;
}
else
{
this.el_usernameCmt.innerHTML = divbox_begin + divbox_end;
}
return valid;
}
};