Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function New-Password {
- param([int]$Length=32, [int]$MinimumSpecialChars)
- # Handle super long password requests
- if($Length -gt 128) {
- if (!$MinimumSpecialChars) {
- # Calculate minimum per 128-character segment
- $MinimumSpecialChars = $Length/(6/($Length/128))
- } else {
- $MinimumSpecialChars = ($MinimumSpecialChars+($Length/128))/($Length/128)
- }
- $pwd = ""
- do {
- $PieceLength = if ($Length -gt 128) { 128 } else { $Length }
- if ($MinimumSpecialChars -gt $PieceLength) {
- $MinimumSpecialChars = $PieceLength
- }
- $pwd += [System.Web.Security.Membership]::GeneratePassword($PieceLength, $MinimumSpecialChars)
- $Length -= 128
- } While ($Length -gt 0)
- return $pwd
- # Normal password requests
- } else {
- if (!$MinimumSpecialChars) {
- $MinimumSpecialChars = $Length/6
- } elseif ($MinimumSpecialChars -gt $Length) {
- $MinimumSpecialChars = $Length
- }
- return [System.Web.Security.Membership]::GeneratePassword($Length, $MinimumSpecialChars)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement