Skip to content

Instantly share code, notes, and snippets.

@45413
Created June 11, 2019 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 45413/9fc7726f054810cf49b8471a7b986e76 to your computer and use it in GitHub Desktop.
Save 45413/9fc7726f054810cf49b8471a7b986e76 to your computer and use it in GitHub Desktop.
Generate Random Passwords using XKPasswd
<#
.SYNOPSIS
Use XKPasswd.net to generate random passwords
.DESCRIPTION
Use XKPasswd.net and the XKCD strong password algorithm to generate
easy to remember high entropy passwords
.EXAMPLE
# Generate 4 passwords with 4 words each
New-XKPasswd -Count 4 -Words 4
THOSE-however-havana-ROUND
LISBON-build-CHANCE-doubt
famous-GONE-EFFORT-PICK
MORNING-TRAINING-ESCAPE-NICE
.INPUTS
[int] Count = 1
[int] Words = 4
.OUTPUTS
[String[]]
#>
function New-XKPasswd {
[CmdletBinding(DefaultParameterSetName='default',
SupportsShouldProcess=$true,
PositionalBinding=$false,
ConfirmImpact='Medium')]
[Alias()]
[OutputType([String[]])]
Param (
# Number of of passwords to generate
[Parameter(Mandatory=$false,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
ParameterSetName='default')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[ValidateRange(1,10)]
[int]
$Count=1,
# Number of words per password
[Parameter(Mandatory=$false,
Position=0,
ValueFromPipeline=$true,
ValueFromPipelineByPropertyName=$true,
ValueFromRemainingArguments=$false,
ParameterSetName='default')]
[ValidateNotNull()]
[ValidateNotNullOrEmpty()]
[ValidateScript({$true})]
[ValidateRange(2,10)]
[int]
$Words = 4
)
$requestPayload = @{
a = "genpw"
n = $Count
c = @{
"num_words" = $Words;
"word_length_min" = 4;
"word_length_max" = 8;
"case_transform" = "RANDOM";
"separator_character" = "-";
"padding_digits_before" = 0;
"padding_digits_after" = 0;
"padding_type" = "NONE";
"random_increment" = "AUTO"
} | ConvertTo-Json
}
if ($PSCmdlet.ShouldProcess("https://xkpasswd.net", "Submit request for $Count passwords")) {
$results = Invoke-WebRequest -Uri "https://xkpasswd.net/s/index.cgi" -Method "POST" `
-ContentType "application/x-www-form-urlencoded; charset=UTF-8" -Body $requestPayload
$results = $results.Content | ConvertFrom-Json
$results.passwords
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment