This continues my series of solution posts for the 2008 Scripting Games with my solution for the Advanced Event 5 which was a joke of a challenge — basically you have to run an arbitrary set of password “strength” rules over a string. The rules are not very complete, and result in such vagaries as “PASSword” getting a worse score than “Password” ... and my randomly generated “KiVExXwMxocScnIjUinCTKTA” getting a WORSE score than “PassWord1” ...

Anyway. Here’s the script, just for the sake of completeness. Please don’t use it for anything you care about ;) .


param([string]$password="a")
$score = 13
$words = get-content wordlist.txt;
if($words -contains $password) {
   $score--
   "Password is an actual word"
}

if( $words -contains ($password.SubString(0,$password.Length-1))) {
   $score--
   "Password begins with an actual word"
}

if( $words -contains ($password.SubString(1,$password.Length-1))) {
   $score--
   "Password ends with an actual word"
}

if( $password.contains("0") -and ($words -contains ($password -replace "0","o"))) {
   $score--
   "Password is an actual word, with o=>0 replacement"
}

if( $password.contains("1") -and ($words -contains ($password -replace "1","l"))) {
   $score--
   "Password is an actual word, with l=>1 replacement"
}

if( $password.Length -lt 10 ) {
   $score--
   "Password doesn't have at least 10 characters"
}

if( $password.Length -gt 20 ) {
   $score--
   "Password has more than 20 characters"
}

if( -not ($password -match "\d") ) {
   $score--
   "Password has no numbers"
}

if( -not ($password -cmatch "[A-Z]") ) {
   $score--
   "Password has no uppercase letters"
}

if( -not ($password -cmatch "[a-z]") ) {
   $score--
   "Password has no lowercase letters"
}

if( -not ($password -match "[^a-zA-Z0-9]") ) {
   $score--
   "Password has no symbols"
}

if( $password -cmatch "[a-z]{4}" ) {
   $score--
   "Password has four consecutive lowercase letters"
}

if( $password -cmatch "[A-Z]{4}" ) {
   $score--
   "Password has four consecutive uppercase letters"
}

if($password.ToCharArray() | group -case | ? {$_.Count -gt 1}){
   $score--
   "Password has some duplicate characters"
}

if($score -le 6)
{"Your password score of $score indicates a weak password."}
elseif(($score -gt 6) -and ($score -lt 11))
{"Your password score of $score indicates a moderately-strong password."}
elseif($score -ge 11)
{"Your password score of $score indicates a strong password."}

Comments are closed.