-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpass.ps1
30 lines (26 loc) · 1.15 KB
/
pass.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
param($length)
function Get-RandomCharacters($length, $characters) {
$random = 1..$length | ForEach-Object { Get-Random -Maximum $characters.length }
$private:ofs=""
return [String]$characters[$random]
}
function Get-EightCharactersPassword() {
$password = Get-RandomCharacters -length 5 -characters 'abcdefghiklmnoprstuvwxyz'
$password += Get-RandomCharacters -length 1 -characters '!@#$%&_-+=\(){}:;"<>?/'
$password += Get-RandomCharacters -length 1 -characters 'ABCDEFGHKLMNOPRSTUVWXYZ'
$password += Get-RandomCharacters -length 1 -characters '1234567890'
return $password
}
if($length -eq $null -or $length -eq 8){
return Get-EightCharactersPassword
}
elseif($length > 9){
$characters = $characters = 'abcdefghiklmnoprstuvwxyz1234567890!@#$%&_-+=\(){}:;"<>?/ABCDEFGHKLMNOPRSTUVWXYZ'
$password = Get-EightCharactersPassword
$password += Get-RandomCharacters -length $length-8 -characters $characters
return $password
}
else{
$characters = $characters = 'abcdefghiklmnoprstuvwxyz1234567890!@#$%&_-+=\(){}:;"<>?/ABCDEFGHKLMNOPRSTUVWXYZ'
return Get-RandomCharacters -length $length -characters $characters
}