Page 1 of 1 1
Topic Options
#77367 - 2003-11-12 11:00 PM Need some help with this script.
kncowans Offline
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
#77368 - 2003-11-13 04:44 AM Re: Need some help with this script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
well...
if all the chars could be the same, you could use simple for loop but as there is need for different.. dunno.
_________________________
!

download KiXnet

Top
#77369 - 2003-11-13 05:06 AM Re: Need some help with this script.
Lonkero Administrator Offline
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
#77370 - 2003-11-13 05:31 AM Re: Need some help with this script.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
I think this would make a great mini-putt challenge ... write a UDF that generates passwords based on an input mask, like this:

$password = MakePassword("XX999")

where X=LETTER, 9=NUMBER and A=ALPHA and assumes nothing is duplicated ... just a thought.

Top
#77371 - 2003-11-13 05:34 AM Re: Need some help with this script.
Howard Bullock Offline
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]

[ 13. November 2003, 05:35: Message edited by: Howard Bullock ]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#77372 - 2003-11-13 05:57 AM Re: Need some help with this script.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
eh Howard ? feel like hitting the old driving range for a few days ? [Wink] I don't know - what you think ?
Top
#77373 - 2003-11-13 06:24 AM Re: Need some help with this script.
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
no hashes allowed [Big Grin]
_________________________
!

download KiXnet

Top
#77374 - 2003-11-13 01:32 PM Re: Need some help with this script.
Richard H. Administrator Offline
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 Offline
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. [Wink]
_________________________
Home page: http://www.kixhelp.com/hb/

Top
#77376 - 2003-11-13 02:21 PM Re: Need some help with this script.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
ja, wonderfull work Richard and I was surprised how little code it actually took you to do it - thought it would have been bigger. not sure i like the 11122233 mask thingy though, while it may be the most flexible method, it's not the most intuitive. think i like the XXX999AAA$$$ thingy more. don't have to think about it too much.

[ 13. November 2003, 14:22: Message edited by: Shawn ]

Top
#77377 - 2003-11-13 03:06 PM Re: Need some help with this script.
Richard H. Administrator Offline
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
#77378 - 2003-11-13 04:06 PM Re: Need some help with this script.
kncowans Offline
Getting the hang of it

Registered: 2000-11-11
Posts: 98
Loc: Doncaster, UK
Hello all

Just checked back to see if I had any replies.

All I can say is you guys are amazing [Smile]

I have been trying on and off for around a year to come up with something like this.

Well done.

Thanks

Kevin
_________________________
Kevin Cowans Senior ICT Technician The Armthorpe School

Top
#77379 - 2003-11-13 05:56 PM Re: Need some help with this script.
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Glad to see another happy member, cudos to Richard - would like to propose one change though, before this UDF finds its way into the library ...

Just from an intuitive stand-point, would suggest the following meta-chars:

X = Alpha
9 = Numeric
L = Alphanumeric
* = Any Char (Wildcard)
@ = Special char (@ or maybe !, whatever)

Just thought that using "*" would intuitively imply a wildcard char, not a special char. Plus this would fill the gap for the missing anychar anyways ... you can tell me to piss off any time.

-Shawn

[ 13. November 2003, 18:01: Message edited by: Shawn ]

Top
#77380 - 2003-11-13 06:00 PM Re: Need some help with this script.
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Nah, piss on [Wink]

Very good suggestion, will make a fine UDF.
_________________________
There are two types of vessels, submarines and targets.

Top
#77381 - 2003-11-13 06:10 PM Re: Need some help with this script.
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
I don't like the alphanumeric bit. Mainly cuz I need the L
How about a case constraint?
U = UPPERcase alpha
l = lowercase alpha
m = (either) MiXEdcase alpha

Maybe could go with separate include and exclude filters. (brain fart)
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1188 anonymous users online.
Newest Members
StuTheCoder, M_Moore, BeeEm, min_seow, Audio
17884 Registered Users

Generated in 0.071 seconds in which 0.031 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org