var bCheckNumbers = true;
var bCheckUpperCase = true;
var bCheckLowerCase = true;
var bCheckPunctuation = true;
var nPasswordLifetime = 365;


function PasswordSecurityLevel(pass){
 var level = 0,
  length = pass.length,
  re = PasswordSecurityLevel,
  check = [re.all.test(pass), re.alu.test(pass), re.num.test(pass)],
  i, chars, key;
 switch(true){
  case length > 7:  level++;
   break;
 };
 if(re.oth.test(pass))
  level++;
 if(check[0] && check[1] && check[2])
  level++;
 if((check[0] && check[1]) || (check[0] && check[2]) || (check[1] && check[2]))
  level++;
 if(level > 5) {
  for(i = 0, chars = {}; i < length; i++)
   chars[pass.charCodeAt(i).toString()] = true;
  i = 0;
  for(key in chars)
   i += chars.hasOwnProperty(key) ? 1 : 0;
  switch(true){
   case i > 9:  level++;
   case i > 7:  level++;
    break;
  };
 };
 return level;
};
PasswordSecurityLevel.num = /[0-9]/;
PasswordSecurityLevel.all = /[a-z]/;
PasswordSecurityLevel.alu = /[A-Z]/;
PasswordSecurityLevel.oth = /[^a-zA-Z0-9]/;

 
// Runs password through check and then updates GUI 
function runPassword(strPassword, strFieldID) 
{
	// Check password
	nPerc = PasswordSecurityLevel(strPassword);
	
	 // Get controls
    	var ctlBar = document.getElementById(strFieldID + "_bar"); 
    	var ctlText = document.getElementById(strFieldID + "_text");
    	if (!ctlBar || !ctlText)
    		return;
    	
    	// Set new width
    	var nRound = Math.round(nPerc * 100);
	if (nRound < (strPassword.length * 5)) 
	{ 
		nRound += strPassword.length * 5; 
	}
    	ctlBar.style.width = 100 + "%";
 
 	// Color and text
 	if (nRound > 299)
 	{
 		strText = "Very Secure";
 		strColor = "#3bce08";
 	}
 	else if (nRound > 199)
 	{
 		strText = "Secure";
 		strColor = "orange";
	}
 	else if (nRound > 99)
 	{
 		strText = "Mediocre";
 		strColor = "#ffd801";
 	}
 	else
 	{
 		strColor = "red";
 		strText = "Insecure";
 	}
	ctlBar.style.backgroundColor = strColor;
	ctlText.innerHTML = "<span style='color: " + strColor + ";'>" + strText + "</span>";
}
 
// Checks a string for a list of characters
function doesContain(strPassword, strCheck)
 {
    	nCount = 0; 
 
	for (i = 0; i < strPassword.length; i++) 
	{
		if (strCheck.indexOf(strPassword.charAt(i)) > -1) 
		{ 
	        	nCount++; 
		} 
	} 
 
	return nCount; 
} 
 
 
 
 
 


