Advertisement
filimonic

PowerShell password complexity test with regular expressions

Jun 14th, 2014
419
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #RegEx for password for CMatch (Case-Sensitive match)
  2. # * Must have at least one digit
  3. # * Must have at least one alhabetical symbol in lower case
  4. # * Must have at least one alhabetical symbol in upper case
  5. # * Must be at least 8 characters long
  6. # (!) Warning, regex uses LookBehind logic. Google for "RegEx LookBehind"
  7. $regEx = '^(?<PASS>.{8,})(?<=.*[A-Z].*)(?<=.*[a-z].*)(?<=.*[0-9].*)$'
  8.  
  9. #Password list
  10. $passwords = @( @'
  11. Aa1234567
  12. aA123456
  13. 213A41a34
  14. 123567Aa
  15. 123Aa
  16. 1223aA
  17. 12234567aA
  18. ERR1234
  19. err
  20. erRrR
  21. 3333333
  22. '@ -split "`r`n" )
  23.  
  24. #CHecking list
  25. forEach ($s in $passwords )
  26. {
  27.     Write-Host -ForegroundColor Gray "Checking [$($s)]...`t" -NoNewline
  28.     if ($s -CMatch $regEx) {
  29.        
  30.         Write-Host -ForegroundColor Green "[$($Matches['PASS'])]:GOOD"
  31.     } else {
  32.         Write-Host -ForegroundColor Red "[$($s)]:BAD"
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement