Created
August 15, 2020 02:39
-
-
Save chrdek/01e136b80582fd88ec0531b169e216f0 to your computer and use it in GitHub Desktop.
Several methods to generate passwords with powershell
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
<# Methods for generating secure passwords with various types of security #> | |
# Password length 10, alphanumeric with symbols | |
$var = @("a","f","G","A","4""\","$","0","1","9","4","2",":F","3","..>","5","m","'","<",".","k","8","7","i",";","K","l","=","+"); $output=""; | |
0..10 | %{ $output+=$var[$(Get-Random -Maximum 10)]; } | |
# Password length 10, SHA-256 derived OTP | |
(Get-Random) > "./tempcode.hash"; "$($((Get-FileHash -Path "./tempcode.hash").Hash)[0..10] + '')"-replace " ",([String]::Empty); | |
# Password length 10 in alphanumeric format, using uppercase and lowercase letters | |
$mainString=@("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","6","7","8","9"); $password=""; | |
for ($o=0; $o -le 10; $o++) { | |
$value= (Get-Random -Maximum 10); | |
$part= (Get-Random -Maximum 35); | |
if (($value % 2) -eq 0) { | |
$password+=[Char]::ToUpperInvariant($mainString[$part]); | |
} else { | |
$password+=$mainString[$part]; | |
} | |
} | |
# Password length 10 in Base64 format | |
"$([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(([Guid]::NewGuid().Guid -replace "-", [String]::Empty)))[0..10] + '')" -replace " ","" | |
# Generalized standard GUID | |
(([Guid]::NewGuid()).Guid -replace "-","") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment