Improve list-random-passwords.ps1 and list-random-pins.ps1

This commit is contained in:
Markus Fleschutz 2021-04-14 13:52:19 +02:00
parent c5fa0b574d
commit 62741a1fba
2 changed files with 9 additions and 15 deletions

View File

@ -1,21 +1,20 @@
#!/usr/bin/pwsh
<#
.SYNTAX list-random-passwords.ps1
.SYNTAX list-random-passwords.ps1 [<password-length>] [<columns>] [<rows>]
.DESCRIPTION prints a list of random passwords
.LINK https://github.com/fleschutz/PowerShell
.NOTES Author: Markus Fleschutz / License: CC0
#>
$PasswordLength = 15
$Columns = 6
$Lines = 24
param([int]$PasswordLength = 15, [int]$Columns = 6, [int]$Rows = 26)
$MinCharCode = 33
$MaxCharCode = 126
try {
write-output ""
$Generator = New-Object System.Random
for ($j = 0; $j -lt $Lines; $j++) {
for ($j = 0; $j -lt $Rows; $j++) {
$Line = ""
for ($k = 0; $k -lt $Columns; $k++) {
for ($i = 0; $i -lt $PasswordLength; $i++) {

View File

@ -6,22 +6,17 @@
.NOTES Author: Markus Fleschutz / License: CC0
#>
param([int]$PinLength = 5, [int]$Columns = 12, [int]$Rows = 24)
function GeneratePIN {
$Generator = New-Object System.Random
for ($i = 0; $i -lt $PinLength; $i++) {
$PIN += [char]$Generator.next(48,57)
}
return $PIN
}
param([int]$PinLength = 5, [int]$Columns = 12, [int]$Rows = 26)
try {
write-output ""
$Generator = New-Object System.Random
for ($j = 0; $j -lt $Rows; $j++) {
$Line = ""
for ($k = 0; $k -lt $Columns; $k++) {
$Line += GeneratePIN
for ($i = 0; $i -lt $PinLength; $i++) {
$Line += [char]$Generator.next(48,57)
}
$Line += " "
}
write-output $Line