Question
· Mar 24, 2022

generate random password

Hello!

I need to create strong random password including letters and integers. Does Cache Object Script has methods to generate password or I have to create my own method ?

$ZV: Cache for UNIX (Red Hat Enterprise Linux for x86-64) 2017.2.2 (Build 867_4_20165U) Mon Aug 17 2020 11:28:28 EDT
Discussion (6)0
Log in or sign up to continue

Julian,

I've tested the method above, and depending on a user's needs, it may not be the best fit. I've run it several times, and I've not seen a lower case character and it's really 'heavy' on the punctuation, some of which may not work well with some websites' password requirements. Here's one example:

ZZZ>W ##CLASS(%PopulateUtils).VarString(120)
%%XDY^F;="#GO=A<B89&K\ZE&3192R8J+9QFO#7J>M0+W=JW%^CL%BGO.1.W1EJ@7Z3,HS0F(<E?UIAE*+[3"CLD$"'\U

Token,

Years ago I created a password generator utility - it's by no means perfect and it's kind of 'tailored' to my use - I do prefer passwords that alternate left hand then right hand to attempt a bit easier manual typing, and even then the randomization doesn't always create a good 'mix' of characters, so I usually have the utility print 10 passwords (or more) and then I choose the 'best' for character mix, punctuation, etc. The routine could be modified for longer passwords, more/different punctuation characters, etc. It's not the _most_ secure, but it works well for my purposes. Feel free to use/modify it, but use it at your own risk. :-)

 PASSWD() ; 
 LEFT,RIGHT,CENTER,LORR,I,J,PASSWD
 LEFT="QAZWSXEDCRFVTGBqazwsxedcrfvtgb234"
 RIGHT="YHNUJMIK,OL.Pyhnujmikolp789"
 CENTER="123456789*-+"
 LORR=$R(2)
 PASSWD=""
 LORR D
 . I=1:1:4 D
 . . PASSWD=PASSWD_$E(LEFT,($R($L(LEFT))+1))_$E(RIGHT,($R($L(RIGHT))+1))
 E  D
 . I=1:1:4 D
 . . PASSWD=PASSWD_$E(RIGHT,($R($L(RIGHT))+1))_$E(LEFT,($R($L(LEFT))+1))
 I=1:1:4 D
 . PASSWD=PASSWD_$E(CENTER,($R($L(CENTER))+1))
 PASSWD
 ;
LOTS(HOWMANY)
 I,J,PASSWD
 +$G(HOWMANY)=0 HOWMANY=10
 ! I=1:1:HOWMANY $$PASSWD,!
 !
 Q
 ;

To run the utility for one password, just execute this:

W $$^PASSWD

But, I generally just print 10 at a time and choose one. To do that, do the LOTS subroutine (which defaults to 10):

ZZZ>D LOTS^PASSWD
 
J3PwIQnX9*76
nzJWPFyt+31+
[[ snippage for brevity ]]

If you want more than 10, add a parameter for the number of passwords you want:

ZZZ>D LOTS^PASSWD(20)

Hope this helps!