#77374 - 2003-11-13 01:32 PM
Re: Need some help with this script.
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Ok, it looked like a nice little challenge.
Pass the udf a mask to generate a password. The mask may contain the numbers 1, 2 or 4 which correspond to the character class "alpha", "numeric" or "special character". You may add the numbers together, so 3 would mean "alpha or numeric", 7 would mean "any class" and so-on.
And other character will be included in the password as-is. If you need to include one of the numbers 1-7, prefix it with the "\" character.
No character will match the preceeding character.
Some examples:
- funStrongRandom("112222") Two alpha followed by 4 numeric digits: GI8781
- funStrongRandom("11-2222") As above, but the numeric and alpha parts are seperated by a hyphen: GI-8781
- funStrongRandom("11-222\2") As above, but the final digit is a hard-coded '2': GI-8782
- funStrongRandom("114333\\\2") As above, except the seperator is a random special character, the characters following the seperator may be numberic or alpha, and the final constant "2" is prefixed by a "\" character: GI^U2A\2
Break ON SRnd(@MSECS) ; You should use a better seed than this one $=Rnd(1) ; Discard low random funStrongRandom("11-22733\1\2\3") ? Function funStrongRandom($sPasswordMask) $asClasses="ABCDEFGHIJKLMNOPQRSTUVWXYZ","1234567890","!£$$%%^&*()-_=+[]{};:'@@#~,<.>/?\|" $funStrongRandom="" ; Initialise as string While $sPasswordMask $iClass=CInt(Left($sPasswordMask,1)) Select Case $iClass AND $iClass<8 ; Use a random character. $sPossibles=IIF($iClass & 1,$asClasses[0],"") $sPossibles=$sPossibles+IIF($iClass & 2,$asClasses[1],"") $sPossibles=$sPossibles+IIF($iClass & 4,$asClasses[2],"") Do $sChar=SubStr($sPossibles,1+Rnd(Len($sPossibles)-1),1) Until $sChar<>Right($funStrongRandom,1) $funStrongRandom=$funStrongRandom+$sChar Case Left($sPasswordMask,1)='\' ; Use next character explicitly. $funStrongRandom=$funStrongRandom+SubStr($sPasswordMask,2,1) $sPasswordMask=SubStr($sPasswordMask,2) Case "True" ; Use this character explicitly. $funStrongRandom=$funStrongRandom+Left($sPasswordMask,1) EndSelect $sPasswordMask=SubStr($sPasswordMask,2) Loop EndFunction
|
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 987 anonymous users online.
|
|
|