Last active
December 9, 2022 23:00
-
-
Save lnlyssg/966bf1bcc77d166f97263b61661d4526 to your computer and use it in GitHub Desktop.
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
/* rexx ***************************************************************/ | |
/* */ | |
/* Purpose : Generate a random password. */ | |
/* Author : Andrew Cameron-Heffer */ | |
/* */ | |
/* The REXX can be passed 2 values. */ | |
/* (1) the number of passwords requested (default = 1) */ | |
/* (2) length of each password (default = 8) */ | |
/* */ | |
/* Or, use PWGEN ? to get brief help. */ | |
/* */ | |
/* The password cannot be all upper-case, lower-case, mixed-case or */ | |
/* numeric. National characters '£', '#' and '@' help this happen. */ | |
/* */ | |
/**********************************************************************/ | |
/* receive parameters (count and length) */ | |
/* if it's a number then use it */ | |
/* if not then just set it to 1 */ | |
arg count length . | |
select | |
when count = '' then count = 1 | |
when count = '?' then | |
do | |
say "This REXX generates random passwords. It can be sent two" | |
say "variables: COUNT LENGTH. Default to 1 8-character password." | |
say "PWGEN 4 will generate 4 8-character passwords." | |
say "PWGEN 1 16 will generate 1 16-character password." | |
say "PWGEN 3 12 will generate 3 12-character password." | |
say " " | |
count = 0 | |
end | |
when count < 1 then count = 1 | |
when datatype(count,'N') = 0 then count = 1 | |
otherwise nop | |
end | |
select | |
when length = '' then length = 8 | |
when length < 2 then length = 2 | |
otherwise nop | |
end | |
/* set random letters/numbers */ | |
chars = "abcdefghijklmnopqrstuvwxyz0123456789£#@" || , | |
"ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789£#@" | |
charc = length(chars) | |
/* go round loop for required count */ | |
/* get 8 characters for each password */ | |
/* say the answer to the user */ | |
do a = 1 to count | |
reject = 1 | |
do forever while reject | |
newpw = '' | |
do b = 1 to length | |
num = random(1,charc) | |
let = substr(chars,num,1) | |
newpw = newpw || let | |
end | |
select | |
when datatype(newpw,'N') then reject = 1 /* numeric only */ | |
when datatype(newpw,'L') then reject = 1 /* lower case only */ | |
when datatype(newpw,'M') then reject = 1 /* mixed case only */ | |
when datatype(newpw,'U') then reject = 1 /* upper case only */ | |
otherwise reject = 0 | |
end | |
end | |
say newpw | |
end | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment