Last active
August 17, 2023 00:25
-
-
Save momota/8d7149979fe011b7ee20db243b1d324f to your computer and use it in GitHub Desktop.
This PowerShell script generates a random string for a one-time password and copies it to the clipboard. It is convenient to register in your launcher.
This file contains hidden or 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
param( | |
[Int32] $password_length = 15 | |
) | |
$numbers = 0..9 | |
$lower_case = @('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') | |
$upper_case = $lower_case.toUpper() | |
$symbols = @('-','+','_','@','=','&','$','#','!','?') | |
$inputs = $numbers + $lower_case + $upper_case + $symbols | |
# Round up | |
$count = [Math]::Ceiling($password_length / $inputs.Length * [Math]::Pow(10, 0)) / [Math]::Pow(10, 0) | |
$long_strings = -Join ( | |
1..$count | ForEach-Object { | |
Get-Random -Count $inputs.Length -input $inputs | |
} | |
) | |
$long_strings[0..($password_length-1)] -Join '' | Set-Clipboard; Get-Clipboard | |
Read-Host "Press ENTER to continue..." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment