### FUNCTION: Generate New Complex Password Function generateNewComplexPassword([int]$passwordNrChars) { Process { $iterations = 0 Do { If ($iterations -ge 20) { Logging " --> Complex password generation failed after '$iterations' iterations..." "ERROR" Logging "" "ERROR" EXIT } $iterations++ $pwdBytes = @() $rng = New-Object System.Security.Cryptography.RNGCryptoServiceProvider Do { [byte[]]$byte = [byte]1 $rng.GetBytes($byte) If ($byte[0] -lt 33 -or $byte[0] -gt 126) { CONTINUE } $pwdBytes += $byte[0] } While ($pwdBytes.Count -lt $passwordNrChars) $pwd = ([char[]]$pwdBytes) -join '' } Until (confirmPasswordIsComplex $pwd) Return $pwd } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter