-
Notifications
You must be signed in to change notification settings - Fork 26
/
Get-WifiKey.ps1
48 lines (44 loc) · 1.15 KB
/
Get-WifiKey.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
<#
.Synopsis
Compute a decent wifi key from a memorable string
.DESCRIPTION
This functions is to consistently get a kind of good password
that's always the same when given the same hint. This is so administrators can remember
an easy keyword to pull up the password to hand out to guests quickly but avoiding a
simple to guess password.
.EXAMPLE
Get-WifiKey september
110cea74c
#>
function Get-WifiKey
{
[CmdletBinding()]
[OutputType([string])]
Param
(
# What to use as a hint for the key
[Parameter(Mandatory=$true,
Position=0)]
[string]$hint
, # The length of the returned key
[ValidateRange(1,31)]
[int]$length = 9
)
Begin
{
$Algorithm = new-object -TypeName System.Security.Cryptography.MD5CryptoServiceProvider
$Text = New-Object -TypeName System.Text.UTF8Encoding
}
Process
{
$Key = [System.BitConverter]::ToString(
$Algorithm.ComputeHash(
$text.GetBytes( $hint )
)
).replace('-','').remove($length).ToLower()
}
End
{
Write-Output $Key
}
}