Created
December 15, 2015 17:04
-
-
Save rycuda/4febb4a223b7733964f8 to your computer and use it in GitHub Desktop.
Powershell xkcdesq password generation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Insert-Value { | |
param( | |
[parameter(ValueFromPipeline=$true)][System.Object[]]$array, | |
[int]$position, | |
$value | |
) | |
end{ | |
$upper = ($input.GetUpperBound(0)) | |
if ( $position -eq 0 ) | |
{ return @($value) + $input } | |
elseif ( $position -gt $upper ) | |
{ return $input += @($value) } | |
elseif (( $position -gt 0 ) -and ( $position -le $upper )) | |
{ return $input[0..($position-1)] +@($value)+ $input[($position)..($input.getupperbound(0))]} | |
} | |
} | |
function new-password { | |
param( | |
$wordsource, #should be a file of words to generate passwords from, one word per line | |
[int]$wordcount, #how many words should be in the password | |
[string[]]$punctuationlist=('!','.',',',':',';') #values to be inserted into the generated password for windows complexity purposes | |
) | |
end{ | |
$wordlist = Get-Random -InputObject (get-content $wordsource) -count $wordcount ; | |
$wordlist = $wordlist | ForEach-Object { ' ' + $_ } | |
get-random -count (get-random -minimum 1 -maximum ($wordlist.length)) -InputObject (0..$wordlist.getupperbound(0)) | foreach-object {$wordlist[$_] = (Get-Culture).TextInfo.ToTitleCase($wordlist[$_])} | |
$wordlist = $wordlist | Insert-Value -value ($punctuationlist | get-random) -position (get-random -Maximum ($wordlist.length) -Minimum 1) | |
(-join $wordlist).Trim() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment