« Event 4: Image is Everything | Main | Event 6: Prime Time »

Event 5: You Call that a Strong Password?

I'm not sure how well this one went.  I ran out of time and I'm not very good with regular expressions. Advanced Event 5 for the Microsoft Scripting Games 2008.

   1: '*********************************************************************

   2: ' Script Name: Event5.vbs

   3: '     Version: 1.0

   4: '      Author: Perry Harris (PHactotum)

   5: '     Updated: 10:45 AM Tuesday, February 26, 2008

   6: '     Purpose: Solves the 2008 winter Scripting Games Advance 

   7: '              Event 5: You Call That a Strong Password?

   8: '              

   9: '       Usage: cscript Event5.vbs

  10: '       Notes:

  11: '    Keywords: 

  12: '  versioning: 1.0  Original release

  13: '*********************************************************************

  14: 'Option Explicit

  15: Const ForReading = 1

  16: Dim strPassword

  17: Dim intPassScore

  18: Dim objRegEx

  19: Dim objFS, objFile

  20:  

  21: Set objRegEx = CreateObject("VBScript.RegExp")

  22: intPassScore = 13

  23:  

  24: if WScript.Arguments.Count < 1 then

  25:     WScript.StdOut.Write "Please enter your password to test: "

  26:     strPassword = WScript.StdIn.ReadLine

  27: else

  28:     strPassword = WScript.Arguments(0)

  29: end if

  30:  

  31: 'Open and read our WordList, we'll need this for some of the tests.

  32: Set objFS = CreateObject("Scripting.FileSystemObject")

  33: Set objFile = objFS.OpenTextFile("C:\Scripts\wordlist.txt", ForReading)

  34:  

  35: strAll = objFile.Readall

  36:  

  37: ' Test one: Make sure that the password is not an actual word.

  38:     objRegEx.Pattern = ucase(strPassword) & "\r\n"

  39:     Set colMatches = objRegEx.Execute(ucase(strAll))  

  40:     

  41:     If colMatches.Count > 0 Then

  42:         Wscript.StdOut.WriteLine "Password is found in the dictionary"

  43:         intPassScore = intPassScore - 1

  44:     End If

  45:  

  46: ' Test two: Make sure that the password, minus the last letter, is not an actual word.

  47:     objRegEx.Pattern = ucase(left(strPassword,len(strPassword)-1)) & "\r?\n"

  48:     Set colMatches = objRegEx.Execute(ucase(strAll))  

  49:     

  50:     If colMatches.Count > 0 Then

  51:         Wscript.StdOut.WriteLine "Password, minus the last letter, is found in the dictionary"

  52:         intPassScore = intPassScore - 1

  53:     End If

  54:  

  55: ' Test three: Make sure that the password, minus the first letter, is not an actual word.

  56:     objRegEx.Pattern = "\r\n" & ucase(right(strPassword,len(strPassword)-1)) & "\r\n"

  57:     Set colMatches = objRegEx.Execute(ucase(strAll))  

  58:  

  59:     If colMatches.Count > 0 Then

  60:         Wscript.StdOut.WriteLine "Password, minus the first letter, is found in the dictionary"

  61:         intPassScore = intPassScore - 1

  62:     End If

  63:  

  64: ' Test four: Make sure that the password does not simply substitute 0 (zero) for the letter o (either an uppercase O or a lowercase o).

  65:     if instr(strPassword,"0") then

  66:         objRegEx.Pattern = ucase(replace(strPassword,0,"o")) & "\r\n"

  67:         Set colMatches = objRegEx.Execute(ucase(strAll))  

  68:     

  69:         If colMatches.Count > 0 Then

  70:             Wscript.StdOut.WriteLine "Password is found in the dictionary after replacing zeros with ""o"""

  71:             intPassScore = intPassScore - 1

  72:         End If

  73:     end if

  74:  

  75: ' Test five: Make sure that the password does not simply substitute 1 (one) for the letter l (either an uppercase L or a lowercase l).

  76:     if instr(strPassword,"1") then

  77:         objRegEx.Pattern = ucase(replace(strPassword,1,"l")) & "\r\n"

  78:         Set colMatches = objRegEx.Execute(ucase(strAll))  

  79:         

  80:         If colMatches.Count > 0 Then

  81:             Wscript.StdOut.WriteLine "Password is found in the dictionary after replacing ones with ""l"""

  82:             intPassScore = intPassScore - 1

  83:         End If

  84:     end if

  85:  

  86: ' Test six: Make sure that the password is at least 10 characters long but no more than 20 characters long. 

  87:     If Len(strPassword) < 10 then

  88:         Wscript.StdOut.WriteLine "Password is two short"

  89:         intPassScore = intPassScore - 1

  90:     else if Len(strPassword) > 20 then

  91:             Wscript.StdOut.WriteLine "Password is two short"

  92:             intPassScore = intPassScore - 1

  93:         end if

  94:     end if

  95:  

  96: ' Test seven: Make sure that the password includes at least one number (the digits 0 through 9).

  97:     objRegEx.Pattern = "\d"

  98:     Set colMatches = objRegEx.Execute(strPassword)  

  99:     

 100:     If colMatches.Count = 0 Then

 101:         Wscript.StdOut.WriteLine "Password must contain at least one number (0-9)"

 102:         intPassScore = intPassScore - 1

 103:     End If

 104:  

 105: ' Test eight: Make sure that the password includes at least one uppercase letter.

 106:     objRegEx.Pattern = "[A-Z]"

 107:     Set colMatches = objRegEx.Execute(strPassword)  

 108:     

 109:     If colMatches.Count = 0 Then

 110:         Wscript.StdOut.WriteLine "Password must contain at least one upper case letter"

 111:         intPassScore = intPassScore - 1

 112:     End If

 113:  

 114: ' Test nine: Make sure that the password includes at least one lowercase letter.

 115:     objRegEx.Pattern = "[a-z]"

 116:     Set colMatches = objRegEx.Execute(strPassword)  

 117:     

 118:     If colMatches.Count = 0 Then

 119:         Wscript.StdOut.WriteLine "Password must contain at least one lower case letter"

 120:         intPassScore = intPassScore - 1

 121:     End If

 122: ' Test ten: Make sure that the password includes at least one symbol.

 123:     objRegEx.Pattern = "[^A-Za-z0-9]"

 124:     Set colMatches = objRegEx.Execute(strPassword)  

 125:     

 126:     If colMatches.Count = 0 Then

 127:         Wscript.StdOut.WriteLine "Password must contain at least one symbol"

 128:         intPassScore = intPassScore - 1

 129:     End If

 130:  

 131: ' Test eleven: Make sure that the password does not include four (or more) lowercase letters in succession.

 132:     objRegEx.Pattern = "[a-z]{4,}"

 133:     Set colMatches = objRegEx.Execute(strPassword)  

 134:     

 135:     If colMatches.Count > 0 Then

 136:         Wscript.StdOut.WriteLine "Password contains 4 or more lower case letters in succession"

 137:         intPassScore = intPassScore - 1

 138:     End If

 139:  

 140: ' Test twelve: Make sure that the password does not include four (or more) uppercase letters in succession.

 141:     objRegEx.Pattern = "[A-Z]{4,}"

 142:     Set colMatches = objRegEx.Execute(strPassword)  

 143:     

 144:     If colMatches.Count > 0 Then

 145:         Wscript.StdOut.WriteLine "Password contains 4 or more upper case letters in succession"

 146:         intPassScore = intPassScore - 1

 147:     End If

 148:  

 149: ' Test thirteen: Make sure that the password does not include any duplicate characters.

 150:     objRegEx.Pattern = "(.)(.*\1)"

 151:     Set colMatches = objRegEx.Execute(strPassword)  

 152:     

 153:     If colMatches.Count > 0 Then

 154:         Wscript.StdOut.WriteLine "Password contains duplicate characters"

 155:         intPassScore = intPassScore - 1

 156:     End If

 157:  

 158: 'Final Score

 159: WScript.StdOut.WriteLine

 160: WScript.StdOut.Write "A password score of " & intPassScore

 161: Select case intPassScore

 162:     case 11,12,13

 163:         WScript.StdOut.WriteLine " indicates a strong password."

 164:     case 7,8,9,10

 165:         WScript.StdOut.WriteLine " indicates a moderately-strong password."

 166:     case else

 167:         WScript.StdOut.WriteLine " indicates a weak password."

 168: End select


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

About

This page contains a single entry from the blog posted on February 26, 2008 5:03 PM.

The previous post in this blog was Event 4: Image is Everything.

The next post in this blog is Event 6: Prime Time.

Many more can be found on the main index page or by looking through the archives.

Powered by
Movable Type 4.1