public/Test-GzPassword.ps1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
function Test-GzPassword() { Param( [Char[]] $Characters, [ScriptBlock] $Validate ) if(!$characters -or $characters.Length -eq 0) { return $false; } if($Validate -ne $null) { & $Validate -Characters $Characters; } $lower = $false; $upper = $false; $digit = $false; $special = $false; $others = "~`&%$#@*+=|\/,:;^_-[]{}()<> " for($i = 0; $i -lt $characters.Length; $i++) { if($lower -and $upper -and $digit -and $special) { return $true; } $char = [char]$characters[$i]; if([Char]::IsDigit($char)) { $digit = $true; continue; } if([Char]::IsLetter($char)) { if([Char]::IsUpper($char)) { $upper = $true; continue; } if([Char]::IsLower($char)) { $lower = $true; } } if($others.Contains($char)) { $special = $true; } } return $false; } |