﻿// JScript File

function testPassword(passwd)

{

      var intScore   = 0

      var strVerdict = "weak"

      var strLog     = ""

      var txt1=document.getElementById('txtmsg');     

//label used on the page that will display the password length status   

                  

      // PASSWORD LENGTH

      if (passwd.length<8) 

// length 8 or less

      {

            intScore = (intScore+6)

            strLog   = strLog + "3 points for length (" + passwd.length + ")\n"

      }

      /*

      else if (passwd.length>4 && passwd.length<8) // length between 5 and 7

      {

            intScore = (intScore+12)

            strLog   = strLog + "6 points for length (" + passwd.length + ")\n"

      }

      */

      else if (passwd.length>7 && passwd.length<26)

// length between 8 and 25

      {

            intScore = (intScore+60)

            strLog   = strLog + "12 points for length (" + passwd.length + ")\n"

      }

      /*

      else if (passwd.length>15) // length 16 or more

      {

            intScore = (intScore+36)

            strLog   = strLog + "18 point for length (" + passwd.length + ")\n"

      }

      */

      // 

      if (passwd.match(/[a-z]/))  

// [verified] at least one lower case letter

      {

            intScore = (intScore+2)

            strLog   = strLog + "1 point for at least one lower case char\n"

      }           

      if (passwd.match(/[A-Z]/))  

// [verified] at least one upper case letter

      {

            intScore = (intScore+10)

            strLog   = strLog + "5 points for at least one upper case char\n"

      }           

      // NUMBERS

      if (passwd.match(/\d+/)) 

// [verified] at least one number

      {

            intScore = (intScore+10)

            strLog   = strLog + "5 points for at least one number\n"

      }           

      /*

      if (passwd.match(/(.*[0-9].*[0-9].*[0-9])/)) // [verified] at least three numbers

      {

            intScore = (intScore+10)

            strLog   = strLog + "5 points for at least three numbers\n"

      }

      */    

      // SPECIAL CHAR

      if (passwd.match(/.[(,),!,@,#,$,%,^,&,*,|,?,_,~]/)) 

// [verified] at least one special character

      {

            intScore = (intScore+10)

            strLog   = strLog + "5 points for at least one special char\n"

      }           

      

      if (passwd.match(/(.*[(,),!,@,#,$,%,^,&,*,|,?,_,~].*[(,),!,@,#,$,%,^,&,*,|,?,_,~])/))

// [verified] at least two special characters

      {

            intScore = (intScore+10)

            strLog   = strLog + "5 points for at least two special chars\n"

      }     

      // COMBOS

      if (passwd.match(/([a-z].*[A-Z])|([A-Z].*[a-z])/)) 

// [verified] both upper and lower case

      {

            intScore = (intScore+4)

            strLog   = strLog + "2 combo points for upper and lower letters\n"

      }

      if (passwd.match(/([a-zA-Z])/) && passwd.match(/([0-9])/)) 

// both letters and numbers

      {

            intScore = (intScore+4)

            strLog   = strLog + "2 combo points for letters and numbers\n"

      }

      //  letters, numbers, and special characters

      if (passwd.match(/([a-zA-Z0-9].*[!,@,#,$,%,^,&,*,?,_,~])|([!,@,#,$,%,^,&,*,?,_,~].*[a-zA-Z0-9])/))

      {

            intScore = (intScore+4)

            strLog   = strLog + "2 combo points for letters, numbers and special chars\n"

      }     

      var progressBar = document.getElementById("progressBar");

//bar used to show status

      progressBar.style.width = intScore +  "%"

      //alert(intScore);

      //alert(progressBar.style.width);

      

      if(intScore < 7 && intScore > 1)

      //if the score calculated is between 1 and 7, then nothing will be displayed

      //calculation is for 1 and 7 because we have started scores with min 8 (see line 9)

      {

            txt1.innerHTML = "";

            progressBar.style.backgroundColor = "white";

            txt1.style.color = "white";                     

      }           

      if(passwd.length < 4 && intScore > 6 && intScore < 32)

      //if the score calculated is between 7 and 31 and password length is less than 4,

      //then status will be displayed as 'Too Short'. The status will be displayed as 'Too Short'

      //upto 4 characters. This can be changed as per the requirement

      {                       

            txt1.innerHTML = "Too Short"

         //alert(txt1.innerHTML);

         progressBar.style.backgroundColor = "white";

         txt1.style.color = "#660033";

      }

      else if (passwd.length < 4 && intScore > 31 && intScore < 51)

      //if the score calculated is between 32 and 50 and password length is less than 4,

      //then again status will be displayed as 'Too Short'. The status will be displayed as 'Too Short'

      //upto 4 characters. This can be changed as per the requirement including the colors of status displayed

      {              

            txt1.innerHTML = "Too Short"

            progressBar.style.backgroundColor = "white";

          txt1.style.color = "#660033";

      }     

      else if(intScore > 7 && intScore < 22)

      //if the score calculated is between 8 and 21, then the status will be displayed as 'Weak'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Weak"

            progressBar.style.backgroundColor = "Red";

          txt1.style.color = "Red";          

      }           

      else if(intScore > 21 && intScore < 32)

      //if the score calculated is between 22 and 31, then the status will be displayed as 'Fair'

      //This can be changed as per the requirement including the colors of status displayed

      {

         txt1.innerHTML = "Fair"

         progressBar.style.backgroundColor = "#FFA346";

         txt1.style.color = "#FFA346";             

      }

      else if (intScore > 31 && intScore < 50)

      //if the score calculated is between 32 and 49, then the status will be displayed as 'Fair'

      //This can be changed as per the requirement including the colors of status displayed

      {

         txt1.innerHTML = "Fair"

         progressBar.style.backgroundColor = "#FFA346";

         txt1.style.color = "#FFA346";

      }

      else if (intScore > 49 && intScore < 60)

      //if the score calculated is between 50 and 59, then the status will be displayed as 'Good'

      //This can be changed as per the requirement including the colors of status displayed

      {

         txt1.innerHTML = "Good"

         progressBar.style.backgroundColor = "blue";

         txt1.style.color = "blue";

      }           

      else if (intScore > 59 && intScore < 61)

      //if the score calculated is between 60 and 61, then the status will be displayed as 'Good'

      //This can be changed as per the requirement including the colors of status displayed

      {

         txt1.innerHTML = "Good"

         progressBar.style.backgroundColor = "blue";

         txt1.style.color = "blue";

      }     

      else if(intScore > 60 && intScore < 62)

      //if the score calculated is between 61 and 62, then the status will be displayed as 'Good'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Good"

            progressBar.style.backgroundColor = "blue";

            txt1.style.color = "blue";

      }           

      else if(intScore > 61 && intScore < 63)

      //if the score calculated is 62, then the status will be displayed as 'Fair'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Fair"

            progressBar.style.backgroundColor = "#FFA346";

            txt1.style.color = "#FFA346";

      }     

      else if (intScore > 62 && intScore < 70)

      //if the score calculated is between 63 and 69, then the status will be displayed as 'Good'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Good"

          progressBar.style.backgroundColor = "blue";

            txt1.style.color = "blue";

      }           

      else if (intScore > 69 && intScore < 71)

      //if the score calculated is 70, then the status will be displayed as 'Fair'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Fair"

            progressBar.style.backgroundColor = "#FFA346";

            txt1.style.color = "#FFA346";

      }           

      else if (intScore > 70 && intScore < 98)

      //if the score calculated is between 71 and 97, then the status will be displayed as 'Good'

      //This can be changed as per the requirement including the colors of status displayed

      {

            txt1.innerHTML = "Good"

            progressBar.style.backgroundColor = "blue";

            txt1.style.color = "blue";

      }     

      else if(intScore > 97 && intScore < 101)

      //if the score calculated is between 98 and 100, then the status will be displayed as 'Strong'

      //This can be changed as per the requirement including the colors of status displayed

      {             

            txt1.innerHTML = "Strong"

            progressBar.style.backgroundColor = "Green";

            txt1.style.color = "Green";

      }

      else if(intScore > 100)

      //if the score calculated is above 100, then the status will be displayed as 'Strong'

      //This can be changed as per the requirement including the colors of status displayed

      //The progress bar width is set as 98% because in Firefox the right corner upto which 

      //the status bar goes seems to cut off.

      {

            progressBar.style.width = "98%";

            txt1.innerHTML = "Strong"

            progressBar.style.backgroundColor = "Green";

            txt1.style.color = "Green";

      }     

}

/***********************************************
* Cool DHTML tooltip script II- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/

var offsetfromcursorX=12 //Customize x offset of tooltip
var offsetfromcursorY=10 //Customize y offset of tooltip

var offsetdivfrompointerX=10 //Customize x offset of tooltip DIV relative to pointer image
var offsetdivfrompointerY=14 //Customize y offset of tooltip DIV relative to pointer image. Tip: Set it to (height_of_pointer_image-1).

document.write('<div id="dhtmltooltip"></div>') //write out tooltip DIV
document.write('<img id="dhtmlpointer" src="images/arrow2.gif">') //write out pointer image

var ie=document.all
var ns6=document.getElementById && !document.all
var enabletip=false
if (ie||ns6)
var tipobj=document.all? document.all["dhtmltooltip"] : document.getElementById? document.getElementById("dhtmltooltip") : ""

var pointerobj=document.all? document.all["dhtmlpointer"] : document.getElementById? document.getElementById("dhtmlpointer") : ""

function ietruebody(){
return (document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
}

function ddrivetip(thetext, thewidth, thecolor){
if (ns6||ie){
if (typeof thewidth!="undefined") tipobj.style.width=thewidth+"px"
if (typeof thecolor!="undefined" && thecolor!="") tipobj.style.backgroundColor=thecolor
tipobj.innerHTML=thetext
enabletip=true
return false
}
}

function positiontip(e){
if (enabletip){
var nondefaultpos=false
var curX=(ns6)?e.pageX : event.clientX+ietruebody().scrollLeft;
var curY=(ns6)?e.pageY : event.clientY+ietruebody().scrollTop;
//Find out how close the mouse is to the corner of the window
var winwidth=ie&&!window.opera? ietruebody().clientWidth : window.innerWidth-20
var winheight=ie&&!window.opera? ietruebody().clientHeight : window.innerHeight-20

var rightedge=ie&&!window.opera? winwidth-event.clientX-offsetfromcursorX : winwidth-e.clientX-offsetfromcursorX
var bottomedge=ie&&!window.opera? winheight-event.clientY-offsetfromcursorY : winheight-e.clientY-offsetfromcursorY

var leftedge=(offsetfromcursorX<0)? offsetfromcursorX*(-1) : -1000

//if the horizontal distance isn't enough to accomodate the width of the context menu
if (rightedge<tipobj.offsetWidth){
//move the horizontal position of the menu to the left by it's width
tipobj.style.left=curX-tipobj.offsetWidth+"px"
nondefaultpos=true
}
else if (curX<leftedge)
tipobj.style.left="5px"
else{
//position the horizontal position of the menu where the mouse is positioned
tipobj.style.left=curX+offsetfromcursorX-offsetdivfrompointerX+"px"
pointerobj.style.left=curX+offsetfromcursorX+"px"
}

//same concept with the vertical position
if (bottomedge<tipobj.offsetHeight){
tipobj.style.top=curY-tipobj.offsetHeight-offsetfromcursorY+"px"
nondefaultpos=true
}
else{
tipobj.style.top=curY+offsetfromcursorY+offsetdivfrompointerY+"px"
pointerobj.style.top=curY+offsetfromcursorY+"px"
}
tipobj.style.visibility="visible"
if (!nondefaultpos)
pointerobj.style.visibility="visible"
else
pointerobj.style.visibility="hidden"
}
}

function hideddrivetip(){
if (ns6||ie){
enabletip=false
tipobj.style.visibility="hidden"
pointerobj.style.visibility="hidden"
tipobj.style.left="-1000px"
tipobj.style.backgroundColor=''
tipobj.style.width=''
}
}

document.onmousemove=positiontip
