2008 Scripting Games - Advanced Event 5
Event 5: You Call That a Strong Password?
param( [string]$pwd = $(throw "Please specify password"), [string]$wordList = "c:\scripts\WordList.txt" ) $score=13 $ptrn6 = '(.*).{10,20}' ; if($pwd -notmatch $ptrn6) {$score-=1; "Password is less than 10 characters or less than 20 characters"}
$ptrn7 = '\d' ; if($pwd -notmatch $ptrn7) {$score-=1; "Password must contain at least one number"} $ptrn8 = '[A-Z]' ; if($pwd -cnotmatch $ptrn8) {$score-=1; "No uppercase letters in password."} $ptrn9 = '[a-z]' ; if($pwd -cnotmatch $ptrn9) {$score-=1; "No lowercase letters in password."} $ptrn10 = '(?=.*[^A-Za-z0-9])' ; if($pwd -notmatch $ptrn10) {$score-=1; "Password must contain at least one symbol"} $ptrn11 = '[a-z]{4,}' ; if($pwd -cmatch $ptrn11) {$score-=1; "Four consecutive lowercase letters in password."} $ptrn12 = '[A-Z]{4,}' ; if($pwd -cmatch $ptrn12) {$score-=1; "Four consecutive uppercase letters in password."} if ($pwd.ToCharArray() | group | where {$_.count -gt 1}) {$score-=1; "Duplicate letters in password."} $words = cat $wordList if($words -contains $pwd) {$score-=1; "Password can't be an actual word"} if($words -contains $pwd.substring(0,($pwd.length-1))) {$score-=1; "Password minus the last letter, is an actual word"} if($words -contains $pwd.substring(1)) {$score-=11; "Password minus the first letter, is an actual word"} if($words -contains ($pwd -replace 'O','0')) {$score-=1; "Password substitute 0 (zero) for the letter o (either an uppercase O or a lowercase o)"} if($words -contains ($pwd -replace 'L','1')) {$score-=1; "Password does not simply substitute 1 (one) for the letter l (either an uppercase L or a lowercase l)"} Write-Host switch($score){ {$_ -lt 7} {"A password score of $score indicates a weak password."; break} {($_ -ge 7) -and ($_ -le 10)} {"A password score of $score indicates a moderately-strong password"; break} {$_ -ge 11} {"A password score of $score indicates a strong password."; break} }
No comments:
Post a Comment