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 ?
Comments
Hey Token.
You could use ##class(%PopulateUtils).VarString() to generate the random string.
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$"'\UToken,
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() ; N LEFT,RIGHT,CENTER,LORR,I,J,PASSWD S LEFT="QAZWSXEDCRFVTGBqazwsxedcrfvtgb234" S RIGHT="YHNUJMIK,OL.Pyhnujmikolp789" S CENTER="123456789*-+" S LORR=$R(2) S PASSWD="" I LORR D . F I=1:1:4 D . . S PASSWD=PASSWD_$E(LEFT,($R($L(LEFT))+1))_$E(RIGHT,($R($L(RIGHT))+1)) E D . F I=1:1:4 D . . S PASSWD=PASSWD_$E(RIGHT,($R($L(RIGHT))+1))_$E(LEFT,($R($L(LEFT))+1)) F I=1:1:4 D . S PASSWD=PASSWD_$E(CENTER,($R($L(CENTER))+1)) Q PASSWD ;LOTS(HOWMANY) N I,J,PASSWD I +$G(HOWMANY)=0 S HOWMANY=10 W ! F I=1:1:HOWMANY W $$PASSWD,! W ! 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!
Thank you Roger!
I have saved method as generatePass.mac , after executing W $$^PASSWD . I've got error
W $$^PASSWD - Error <NOROUTINE>
Token,
If you saved it as generatePass.mac and compiled it, try this to generate a single password:
W $$^generatePass
and if you wanted to generate 20 passwords, you'd call it like this:
D LOTS^generatePass(20)
Hope this helps!
Have a look at this project and this article
Thank you!