|
2 | 2 | RANDOM PASSWORD GENERATION
|
3 | 3 | A macro program that generates a random password based on a list of allowed characters.
|
4 | 4 | Keywords: Macro
|
5 |
| - SAS Versions: SAS 9, SAS Viya |
| 5 | + SAS Versions: SAS 9, SAS Viya |
6 | 6 | Documentation: https://go.documentation.sas.com/doc/en/pgmsascdc/default/mcrolref/titlepage.htm
|
7 | 7 | 1. Define keyword arguments control the length and characters used in the password.
|
8 | 8 | 2. Build a macro variable containing all allowed characters.
|
9 | 9 | 3. In a loop, use %SUBSTR(%SYSFUNC(RAND)) to select random characters...
|
10 | 10 | 4. ...and append them to the growing password.
|
11 | 11 | 5. Test macro via a simple loop and various settings.
|
12 | 12 | 6. Use a random password for an encryption key on a tempoarary dataset.
|
13 |
| - NOTE: Does not (currently) support unmatched single or double quote characters |
14 |
| - in the special characterw string. Mismatched left or right parentheses have not been |
15 |
| - tested either. |
| 13 | +NOTE: Does not (currently) support unmatched single or double quote characters in the special |
| 14 | + characterw string. Mismatched left or right parentheses have not been tested either. |
16 | 15 | ************************************************************************************************/
|
17 | 16 |
|
18 | 17 | /************************************************************************************************
|
19 | 18 | 1. Define keyword arguments control the length and characters
|
20 | 19 | used in the password.
|
21 | 20 | a. len= is the desired length of the password, defaulting to 24
|
22 |
| - b. digits= is a Boolean flag, defaulting to TRUE. When TRUE (non-zero), |
23 |
| - digits 0-9 are available for use in the password. |
24 |
| - c. special= is a set of special characters to also use in passwords. Defaults |
25 |
| - to those shown in the %NRSTR(). Use special= to not have any specials. |
| 21 | + b. digits= is a Boolean flag, defaulting to TRUE. When TRUE (non-zero), |
| 22 | + digits 0-9 are available for use in the password. |
| 23 | + c. special= is a set of special characters to also use in passwords. Defaults |
| 24 | + to those shown in the %NRSTR(). Use special= to not have any specials. |
26 | 25 | ************************************************************************************************/
|
27 | 26 |
|
28 | 27 | %MACRO RANDPASS(len=24,digits=1,special=%NRSTR(@%&#!?.-_+*,/;:));
|
|
35 | 34 | /************************************************************************************************
|
36 | 35 | 2. Build a macro variable containing all allowed characters.
|
37 | 36 | a. Add the lowercase letters.
|
38 |
| - b. Add uppercase characters via %UPCASE(). |
39 |
| - c. Add digits, if requested. |
40 |
| - d. Add special characters. Note the use of %SUPERQ() to avoid issues |
41 |
| - with &s and %s that may be present in the string. |
| 37 | + b. Add uppercase characters via %UPCASE(). |
| 38 | + c. Add digits, if requested. |
| 39 | + d. Add special characters. Note the use of %SUPERQ() to avoid issues |
| 40 | + with &s and %s that may be present in the string. |
42 | 41 | ************************************************************************************************/
|
43 | 42 |
|
44 | 43 | %LET chars=abcdefghijklmnopqrstuvwxyz;
|
|
88 | 87 | /************************************************************************************************
|
89 | 88 | 5. Test macro via a simple loop and various settings.
|
90 | 89 | a. We need to define a macro for this. Macro now allows %IF statements in
|
91 |
| - "open code", but not loops. |
92 |
| - b. Just two cases here. All-defaults, plus longer-no-digits-no-specials. |
93 |
| - c. The "test" just prints them to the log, for eyeballing. |
94 |
| - d. Then we run the loop 3 times to get an idea as to what it's doing. |
| 90 | + "open code", but not loops. |
| 91 | + b. Just two cases here. All-defaults, plus longer-no-digits-no-specials. |
| 92 | + c. The "test" just prints them to the log, for eyeballing. |
| 93 | + d. Then we run the loop 3 times to get an idea as to what it's doing. |
95 | 94 | ************************************************************************************************/
|
96 | 95 |
|
97 | 96 | %MACRO TEST(n);
|
|
106 | 105 | /************************************************************************************************
|
107 | 106 | 6. Use a random password for an encryption key on a tempoarary dataset.
|
108 | 107 | a. Generate a longish (60 characters) password, safe from prying eyes.
|
109 |
| - b. Import a list of NSA recruits from a secret location no one has |
110 |
| - ever heard of, and protect it with AES encryption with our generated |
111 |
| - password. |
112 |
| - c. Now we can run analytics on it safely. Run PROC MEANS, and |
113 |
| - then ponder why the recruits are all teenagers. |
114 |
| - d. Drop the table (I used PROC SQL), knowing that even if the |
115 |
| - data was recovered from the disk, the encryption renders it unreadable. |
| 108 | + b. Import a list of NSA recruits from a secret location no one has |
| 109 | + ever heard of, and protect it with AES encryption with our generated |
| 110 | + password. |
| 111 | + c. Now we can run analytics on it safely. Run PROC MEANS, and |
| 112 | + then ponder why the recruits are all teenagers. |
| 113 | + d. Drop the table (I used PROC SQL), knowing that even if the |
| 114 | + data was recovered from the disk, the encryption renders it unreadable. |
116 | 115 | ************************************************************************************************/
|
117 | 116 |
|
118 | 117 | %LET pw=%randpass(len=60);
|
|
0 commit comments