Quick Search:
CODE
Oracle PL/SQL Code Library
JOBS
Find Or Post Oracle Jobs
FORUM
Oracle Discussion & Chat
 JavaScript: Password Strength Tester Jump to:  
Category: >> JavaScript >> Password Strength Tester Bookmark and Share

<< lastnext >>

Snippet Name: Password Strength Tester

Description: This script evaluates a password by checking:

* Length
* Amount/Existence of Numbers
* Capital/Lowercase Ratio (for case-sensitive passwords - as nearly all are)

Comment: (none)

Language: JAVASCRIPT
Highlight Mode: JAVASCRIPT
Last Modified: March 01st, 2009

< s c r ipt type="text/javascript">
FUNCTION PassWord () {
  a=document.getElementById('Password').value ;
  b=0;
  PassWordStrength(a,b) ;
}
FUNCTION PassWordStrength (a,b) {
  //Awards Points for Length
  IF (a.length<12) {
   c=a.length/2 ; l=c.toFixed(0) ; g=0 ;
   WHILE (g<l) {
     b=b+1 ; g=g+1 ;
   }     
  }
  ELSE { b=b+6 ; }
  //This section awards points for existence and number of numbers in the Password Field
  numTest=NEW RegExp("[0-9]","g") ;
  numVal=1 ; c="" ;
  WHILE (numVal!=NULL) {
    numVal=numTest.exec(a) ; c=c+numVal ;
  }
  g=0 ; d="" ;
  IF (c.length-4<2) { b=b+0 ; }
  ELSE IF (c.length-4<4) { b=b+2 ; }
  ELSE IF (c.length-4<8) { b=b+4 ; }
  ELSE { b=b+6 }
  //The final evaluating section will add points for the ratio of Capitalised/LowerCase
  capTest=NEW RegExp("[A-Z]","g") ;
  capVal=1 ; c="" ;  Total="" ;
  WHILE (capVal!=NULL) {
    capVal=capTest.exec(a) ; c=c+capVal ; Total=Total+capVal
  }
  lowerTest=NEW RegExp("[a-z]","g") ;
  lowerVal=1 ; d="" ;
  WHILE (lowerVal!=NULL) {
    lowerVal=lowerTest.exec(a) ; d=d+lowerVal ; Total=Total+lowerVal
  }
  Per=Total.length-8 ; Perc=Per/100 ; Percent=Perc*1 ; Cap=c.length-4 ; Capo=Percent*Cap ; Caps=Capo.toFixed(0) ; Low=d.length-4 ; Lowe=Percent*Low ; Lower=Lowe.toFixed(0) ; difference=Caps-Lower;
  IF (difference<60) {
    dif=difference/10 ; diff=dif.toFixed(0) ; diff=diff-1 ; g=0 ;
    WHILE (g<diff) {
      g=g+1 ; b=b+1 ;
    }
  }
  ELSE { b=b+6 }   
  //This section converts the points gained into a bar
  f=0 ; Bar="" ;
  WHILE (f<b*2) { f=f+1 ; Bar=Bar+"_" ; }
  //And then the Bar into Wording with the Points next to it
  IF (Bar.length&#609;) { StrengthFinal="<b><font color='red'>WEAK</font></b> Points:"+b*2 ; Bar="<font color='red'>"+Bar+"</font>" ;}
  ELSE IF (Bar.length&#6018;) { StrengthFinal="<b><font color='CC6600'>MODERATE</font></b>   Points:"+b*2; Bar="<font color='CC6600'>"+Bar+"</font>" ;}
  ELSE IF (Bar.length&#6024;) { StrengthFinal="<b><font color='FF9933'>MODERATELY-STRONG</font></b>   Points:"+b*2; Bar="<font color='FF9933'>"+Bar+"</font>" ;}
  ELSE { StrengthFinal="<b><font color='green'>STRONG</font></b>   Points:"+b*2; Bar="<font color='green'>"+Bar+"</font>" }
  //The area below defines where the information about the password is put.
  document.getElementById('Strength Box').innerHTML=StrengthFinal ;
  document.getElementById('Strength Visual').innerHTML=Bar ;
}
</script>
 
<body><div style="background-color:FFF5CF; position: absolute; width: 461px; height: 36px; z-index: 1; left: 11px; top: 14px" id="PassWord Field">
<div style="position: absolute; width: 272px; height: 6px; z-index: 3; left: 172px; top: 14px" id="Strength Visual">
    </div>
<div style="position: absolute; width: 271px; height: 12px; z-index: 2; left: 173px; top: 3px" id="Strength Box">
   <font id="Display" size="2">Password Strength:</font></div>
<div style="position: absolute; width: 161px; height: 11px; z-index: 1; left: 6px; top: 7px" id="EntryBox">
<input onkeypress='Javascript:PassWord()' type="password" id="Password"></div>
 </div>
</body>
 
 


Free
Oracle Magazine
Subscriptions
and Oracle White Papers


SQL University.net courses meet the most demanding needs of the business world for advanced education in a cost-effective manner. SQL University.net courses are available immediately for IT professionals and can be taken without disruption of your workplace schedule or processes.

Compared to traditional travel-based training, SQL University.net saves time and valuable corporate resources, allowing companies to do more with less. That's our mission, and that's what we deliver.

Click here to find out more
 
Home      :      Code Library      :      Sponsors      :      Privacy      :      Terms of Use      :      Contact Us 198 users online    © 2009 psoug.org

PSOUG LOGIN
Username: 
Password: 
Forgot your password?