-
Notifications
You must be signed in to change notification settings - Fork 0
/
Get-PassPhrase.ps1
180 lines (146 loc) · 6.19 KB
/
Get-PassPhrase.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<#
.SYNOPSIS
Build Passphrase using dice rolls.
Prerequisites:
1: Tab separated word list file with two columns per row
DiceRoll = 11111-16666, 21111-26666 and so on, up to 61111-66666
Word = single word
Protip: Download eff_large_wordlist.txt from https://www.eff.org/dice
Place wordlist(s) in script folder or subfolder Resources
2: Import the Get-Passphrase.ps1 module using the command
Import-Module .\Get-PassPhrase.ps1 -Force
.LINK
https://github.com/dotBATmanNO/ps-Get-PassPhrase/
.EXAMPLE
PS C:\Scripts\Get-PassPhrase> Import-Module .\Get-PassPhrase.ps1 -Force
PS C:\Scripts\Get-PassPhrase> Get-PassPhrase
BaconAcornMultiply
.EXAMPLE
PS C:\Scripts\Get-PassPhrase> Import-Module .\Get-PassPhrase.ps1 -Force
PS C:\Scripts\Get-PassPhrase> Get-PassPhrase -Words 4 -Space 1
Guide Promenade Epileptic Snowboard
.EXAMPLE
PS C:\Scripts\Get-PassPhrase> Import-Module .\Get-PassPhrase.ps1 -Force
PS C:\Scripts\Get-PassPhrase> Get-WordList -Casing lower
PS C:\Scripts\Get-PassPhrase> Get-PassPhrase -Words 4 -Space 1
number dining shelter landlady
.EXAMPLE
PS C:\Scripts\Get-PassPhrase> Import-Module .\Get-PassPhrase.ps1 -Force
PS C:\Scripts\Get-PassPhrase> "User", "UserName", "UserLongName" | ForEach-Object -Process { Get-PassPhrase -User $_ }
User GearDaycareShed
UserName JaundiceBrookReliable
UserLongName AliasGroomAnteater
.EXAMPLE
PS C:\Scripts\Get-PassPhrase> Import-Module .\Get-PassPhrase.ps1 -Force
PS C:\Scripts\Get-PassPhrase> "User", "UserName", "UserLongName" | ForEach-Object -Process { Get-PassPhrase -Words 4 -Space 1 -User $_ }
User Dimness Crunching Cannon Plausible
UserName Sitter Calm Astronaut Molehill
UserLongName Astronaut Problem Kissable Harmonize
#>
Function Get-Passphrase
{
[CmdletBinding()]
Param (
# Choose the number of words to use for your passphrase.
[Parameter(Position=0)]
[int]$Words = 3,
# Specify if each word should be separated by space.
[Parameter(Position=1)]
[bool]$Space = $false,
# Name the user that needs a new password.
[Parameter(Position=2)]
[string]$User)
<#
.SYNOPSIS
Create a Pass Phrase consisting of X number of words.
.EXAMPLE
Get-Passphrase -Words 3 -Case TitleCase
#>
if ($null -eq $htWordList)
{
try { Get-WordList }
catch { Throw "Script failed to load required resource (wordlist)." }
}
# Repeats X times
for (($i=0), ($strTempPwd = "");$i -lt $Words;$i++)
{
# Roll 5 dice
$iDiceRoll = (Get-Random -Minimum 1 -Maximum 6)*10000
$iDiceRoll += (Get-Random -Minimum 1 -Maximum 6)*1000
$iDiceRoll += (Get-Random -Minimum 1 -Maximum 6)*100
$iDiceRoll += (Get-Random -Minimum 1 -Maximum 6)*10
$iDiceRoll += (Get-Random -Minimum 1 -Maximum 6)*1
# Retrieve corresponding word from Wordlist
$strPassphrase += $htWordList["$iDiceRoll"]
if ( $Space ) { $strPassphrase += " " }
}
# Avoid space at the end of pass phrase!
if ($user)
{ Return "$($User.Padright(22," "))$($strPassphrase.TrimEnd())" }
else
{ Return $strPassphrase.TrimEnd() }
}
Function Get-WordList
{
[CmdletBinding()]
Param (
# Default is to use EFF 5 dice Word List eff_large_wordlist.txt, see https://www.eff.org/dice.
[Parameter(Position=0)]
[string]$WordList = "eff_large_wordlist.txt",
# Select UPPER/lower/TitleCase - leave blank to keep casing from wordlist file.
[Parameter(Position=1)]
[ValidateSet("UPPER", "lower", "Title", "TitleCase", "Proper")]
[string]$Casing = "TitleCase")
$TextInfo = (Get-Culture).TextInfo
$ResourcePath = Split-Path -parent $PSCommandPath # Use the folder the script was started from
If (Test-Path -Path "$ResourcePath\Resources\$WordList" -PathType Leaf)
{
$strWordListFile = "$ResourcePath\Resources\$WordList"
}
else
{
$strWordListFile = "$ResourcePath\$WordList"
}
If (Test-Path -Path $strWordListFile -PathType Leaf)
{
# File Exists, build hashtable
$arrWordList = Import-Csv -path $strWordListFile -Header "DiceRoll", "Word" -Delimiter "`t"
# Define ordered hashtable for diceroll word list
# Ensure variable is not defined already
Remove-Variable -ErrorAction SilentlyContinue htWordList
$global:htWordList = [ordered]@{}
switch ($Casing)
{
$null { for ($i=0;$i -lt $arrWordList.Count;$i++) { $htWordList.Add($arrWordList[$i].DiceRoll, $arrWordList[$i].Word) } } # UsE CaSing fRom wOrD list
"UPPER" { for ($i=0;$i -lt $arrWordList.Count;$i++) { $htWordList.Add($arrWordList[$i].DiceRoll, $TextInfo.ToUpper($arrWordList[$i].Word)) } } # Use UPPERCASE for all words
"lower" { for ($i=0;$i -lt $arrWordList.Count;$i++) { $htWordList.Add($arrWordList[$i].DiceRoll, $TextInfo.ToLower($arrWordList[$i].Word)) } } # Use lowercase for all words
Default { for ($i=0;$i -lt $arrWordList.Count;$i++) { $htWordList.Add($arrWordList[$i].DiceRoll, $TextInfo.ToTitleCase($arrWordList[$i].Word)) } } # Use Title Case For All Words
}
Remove-Variable arrWordList # Remove array holding wordlist file
}
else
{
Write-Host "File not found: $strWordListFile
Issue: Could not locate word list to use for diceroll pass phrase generation!
Pro-tip to help build passphrases that are easy to communicate:
Download the file 'eff_large_wordlist.txt' from https://www.eff.org/dice
The script will default to use this file if present.
Alternatively:
Create a 5 dice wordlist file and place this in script folder (or subfolder Resources).
Name this file using the -WordList parameter
The Wordlist file must hold two columns per row separated by <tab> character.
'DiceRoll' = five dice combinations, starting at 11111 and ending at 66666.
'Word' = corresponding word.
Example (based on eff_large_wordlist.txt):
11111<tab>abacus
[..]
16666<tab>copilot
21111<tab>coping
[..]
26666<tab>five
[..]
66666<tab>zoom
"
Throw
}
}