/* ************************************************************
Created: 20060120
Author:  Steve Moitozo <god at zilla dot us> -- geekwisdom.com
Description: This is a quick and dirty password quality meter
		 written in JavaScript so that the password does
		 not pass over the network.
License: MIT License (see below)
Modified: 20060620 - added MIT License
Modified: 20061111 - corrected regex for letters and numbers
                     Thanks to Zack Smith -- zacksmithdesign.com
---------------------------------------------------------------
Copyright (c) 2006 Steve Moitozo <god at zilla dot us>

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

   The above copyright notice and this permission notice shall
be included in all copies or substantial portions of the
Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.
---------------------------------------------------------------
*/
var carryon = 0;
function passcheck(passwd)
{
		var intScore   = 0
		var strVerdict = "weak"
		var strLog     = ""

		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3);
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6);

		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12);

		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18);

		}


		// 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+5);

		}

		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}

		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5);
		}


		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5);
		}

									 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5);
		}


		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2);
		}

		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		{
			intScore = (intScore+2);
		}

									// [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2);

		}


		if(intScore < 16)
		{
		   strVerdict = "very weak";
		   col= "#0000ff";
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = "weak";
		   col = "#00ff00";
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = "mediocre";
		   col = "#ffff00";
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = "strong";
		   col="#ff8000";
		}
		else
		{
		   strVerdict = "stronger";
		   col="#ff0000";
		}

	if (carryon == 1){
	the_timeout = setTimeout("passcheck(document.forms[3].password.value);",100);
	}

//(intScore)
//(strVerdict)
//(strLog)

x=document.getElementById("pass_strength");
x.style.width = (intScore*4) + "px";
x.style.backgroundColor = col;

y=document.getElementById("ranking");
y.firstChild.nodeValue=strVerdict;
}



function passthecheck(passwd)
{
		var intScore   = 0
		var strVerdict = "weak"
		var strLog     = ""

		// PASSWORD LENGTH
		if (passwd.length<5)                         // length 4 or less
		{
			intScore = (intScore+3);
		}
		else if (passwd.length>4 && passwd.length<8) // length between 5 and 7
		{
			intScore = (intScore+6);

		}
		else if (passwd.length>7 && passwd.length<16)// length between 8 and 15
		{
			intScore = (intScore+12);

		}
		else if (passwd.length>15)                    // length 16 or more
		{
			intScore = (intScore+18);

		}


		// 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+5);

		}

		// NUMBERS
		if (passwd.match(/\d+/))                                 // [verified] at least one number
		{
			intScore = (intScore+5)
		}

		if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/))             // [verified] at least three numbers
		{
			intScore = (intScore+5);
		}


		// SPECIAL CHAR
		if (passwd.match(/.[!,@,#,$,%,^,&,*,?,_,~]/))            // [verified] at least one special character
		{
			intScore = (intScore+5);
		}

									 // [verified] at least two special characters
		if (passwd.match(/(.*[!,@,#,$,%,^,&,*,?,_,~].*[!,@,#,$,%,^,&,*,?,_,~])/))
		{
			intScore = (intScore+5);
		}


		// COMBOS
		if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/))        // [verified] both upper and lower case
		{
			intScore = (intScore+2);
		}

		if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) // [verified] both letters and numbers
		{
			intScore = (intScore+2);
		}

									// [verified] letters, numbers, and special characters
		if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))
		{
			intScore = (intScore+2);

		}


		if(intScore < 16)
		{
		   strVerdict = "very weak";
		   col= "#0000ff";
		}
		else if (intScore > 15 && intScore < 25)
		{
		   strVerdict = "weak";
		   col = "#00ff00";
		}
		else if (intScore > 24 && intScore < 35)
		{
		   strVerdict = "mediocre";
		   col = "#ffff00";
		}
		else if (intScore > 34 && intScore < 45)
		{
		   strVerdict = "strong";
		   col="#ff8000";
		}
		else
		{
		   strVerdict = "stronger";
		   col="#ff0000";
		}

	if (carryon == 1){
	the_timeout = setTimeout("passthecheck(document.forms[3].password.value);",10);
	}

//(intScore)
//(strVerdict)
//(strLog)

x=document.getElementById("pass_strength");
x.style.width = (intScore*4) + "px";
x.style.backgroundColor = col;

y=document.getElementById("ranking");
y.firstChild.nodeValue=strVerdict;
}



function doit(){
carryon=1;
}

function stoppasscheck(){
carryon=0;
}
