#77367 - 2003-11-12 11:00 PM
Need some help with this script.
|
kncowans
Getting the hang of it
Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
|
Hello all
I am trying to write a script that will allow me to create a Password consisting of 2 letters followed by 4 digits where none of the characters are the same as the previous one.
I have succeeded with the script below, however, it is very inflexible as it stands.
I would like to be able to create the first character, store that into an Array, or similar, then create the second, compare that to the previous and so on, however, I do not know how to use Arrays which is a big problem.
Does anybody have a suggestion as to how I can achieve this?
Thanks in advance
Kevin
code:
$Char1 = Character(65,90)
Do
$Char2 = Character(65,90)
Until $Char2 <> $Char1
Do
$Char3 = Character(48,57)
Until $Char3 <> $Char2
Do
$Char4 = Character(48,57)
Until $Char4 <> $Char3
Do
$Char5 = Character(48,57)
Until $Char5 <> $Char4
Do
$Char6 = Character(48,57)
Until $Char6 <> $Char5
$Password = $Char1+$Char2+$Char3+$Char4+$Char5+$Char6
? $Password
Exit
Function Character( $min , $max )
$ = SRnd(@MSECS) $ = Rnd()
$Char = Rnd($max)+$min
Do
$Char = Rnd($max)+$min
Until $Char =>$min AND $Char =<$max
EndFunction
_________________________
Kevin Cowans
Senior ICT Technician
The Armthorpe School
|
|
Top
|
|
|
|
#77369 - 2003-11-13 05:06 AM
Re: Need some help with this script.
|
Lonkero
KiX Master Guru
   
Registered: 2001-06-05
Posts: 22346
Loc: OK
|
k, something like this should do the trick. so, you want fries with that?
code:
$pass = Character(65,90) $pass=$pass+Character(65,90,$pass)
for $=3 to 6 $pass = $pass+Character(48,57,right($pass,1)) next
? $Pass
Exit 0
Function Character( $min , $max, optional $not) dim $,$c $ = SRnd(@MSECS) $ = Rnd()
Do $c = Rnd($max)+$min Until $c =>$min AND $c =<$max and $c<>$not EndFunction
_________________________
!download KiXnet
|
|
Top
|
|
|
|
#77371 - 2003-11-13 05:34 AM
Re: Need some help with this script.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Does this have to be strong passwords as defined by using 3 out of 4 character classes?
Dumb question only two classes were specified. ![[Frown]](images/icons/frown.gif) [ 13. November 2003, 05:35: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#77372 - 2003-11-13 05:57 AM
Re: Need some help with this script.
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
eh Howard ? feel like hitting the old driving range for a few days ? I don't know - what you think ?
|
|
Top
|
|
|
|
#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
|
|
|
|
#77375 - 2003-11-13 01:48 PM
Re: Need some help with this script.
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Boy! Go to bed and wake up to find Tiger Woods already played the course.
|
|
Top
|
|
|
|
#77377 - 2003-11-13 03:06 PM
Re: Need some help with this script.
|
Richard H.
Administrator
   
Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
|
Hah! No sweat.
Same as before, but in addition to the previous rules:
- X = Alpha
- 9 = Numeric
- L = Alphanumeric
- * = Special char
I've used "*" rather than "$" as it is more KiX-friendly
Break ON SRnd(@MSECS) ; You should use a better seed than this one $=Rnd(1) ; Discard low random $s="X9L*" $s "=" funStrongRandom($s) ? Function funStrongRandom($sPasswordMask) $asClasses="ABCDEFGHIJKLMNOPQRSTUVWXYZ","1234567890","!£$$%%^&*()-_=+[]{};:'@@#~,<.>/?\|" $funStrongRandom="" ; Initialise as string While $sPasswordMask $iClass=InStr("1234567\X9L*",Left($sPasswordMask,1)) Select Case Left($sPasswordMask,1)='\' ; Use next character explicitly. $funStrongRandom=$funStrongRandom+SubStr($sPasswordMask,2,1) $sPasswordMask=SubStr($sPasswordMask,2) Case $iClass $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 "True" ; Use this character explicitly. $funStrongRandom=$funStrongRandom+Left($sPasswordMask,1) EndSelect $sPasswordMask=SubStr($sPasswordMask,2) Loop EndFunction
|
[ 13. November 2003, 16:01: Message edited by: Richard H. ]
|
|
Top
|
|
|
|
Moderator: Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 1188 anonymous users online.
|
|
|