Finbom
(Fresh Scripter)
2003-06-27 01:19 PM
Generate password with only letters and numbers?

Hello there!

I'm using Bryce script to generate a password. ( http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=003592#000001 )
The problem is that the software that I need the password for is unable to handle other than letters and numbers in a password.

So Im sitting here trying to find out how to restrict the generator to this.
All I want is a password that only contain LARGE/small letters from a-z and numbers.

Can anyone help to explain how to do this?

regards, Magnus Finbom


LonkeroAdministrator
(KiX Master Guru)
2003-06-27 01:31 PM
Re: Generate password with only letters and numbers?

uhm.
third topic...

anyway, for me the script you linked to just gives numbers and letters.

what else do you get?


Finbom
(Fresh Scripter)
2003-06-27 02:31 PM
Re: Generate password with only letters and numbers?

Hi again!

This script gives all kind of chars in the password.
Examples:

D3llg%F&Bl0
RD/`Gi.(,%0
G8i+*qWS(_0
)?A+~5l6(_0

Good passwords except for that my software cant handle thoose extra chars.

Regards, Magnus


Kdyer
(KiX Supporter)
2003-06-27 02:36 PM
Re: Generate password with only letters and numbers?

Suggestion..

Why not change from -

random(33,126,$seed)

to be -

random(48,125,$seed)

HTH,

Kent


Kdyer
(KiX Supporter)
2003-06-27 02:50 PM
Re: Generate password with only letters and numbers?

This seems to be what you are looking for -

Replace this section:
code:
		$chr = random(48,57,$seed) $seed = $seed - $seedjump
select
case $i = 1
while $chr >= 48 and $chr <=57
$chr = random(65,90,$seed) $seed = $seed + $seedjump
loop
case $i = $length
while $chr >= 48 and $chr <=57
$chr = random(97,122,$seed) $seed = $seed - $seedjump
loop
endselect

It yields the following, for example -
quote:

R44582496u
G28457516u
G28457516u
G28457516u
Z39198601i
Z39737681z
T75737681z
P63765577x
P63765577x
P63765577x
A32616235n
R14044123r
R14044172o
P33878572o
P33878572o
P33878572o
J37771612j
J37771612j
J37771612j
X68075921m
X68075921m
X68075921m
X64728080b
H94728080b
H94720770j
Q94180770j
Q94180770j
Q94132124e
N11232124e
N11232124x
A08829724x
A08829724x
A08829724c
L80578488c
L87451609n
V67451609n
V67451609n
V67456475t
L30576475t
L30576475t
T05651738p
T05651738p
T05651738p
D14433232m
D14433232m
D14433232m
Z69295712w
Z69295712b
T36479085b
T36479085b

I am sure it can be improved upon. [Big Grin]

HTH,

Kent

[ 27. June 2003, 14:52: Message edited by: kdyer ]


Richard H.Administrator
(KiX Supporter)
2003-06-27 02:53 PM
Re: Generate password with only letters and numbers?

This will also work, and will allow you to specify which characters to use easily.

$sTerminal characters are characters which can appear anywhere.
$sNonTerminal characters are characters which must not appear at the start or end of the password.

code:
udfPWGen(10,"Bills login") ?
udfPWGen(5,1999) ?
udfPWGen(20) ?

Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
$sTerminal=$sTerminal+"abcdefghijklmnopqrstuvwxyz"
$sNonTerminal="0123456789"
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd(@TICKS+$iSeed*@YEAR+@YDAYNO)
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom))+1),1))
Next
EndFunction



Finbom
(Fresh Scripter)
2003-06-27 03:25 PM
Re: Generate password with only letters and numbers?

WoW! Never seen this fast answers in a forum before. [Smile]

It works great now!

Thanks!


jtokach
(Seasoned Scripter)
2003-09-02 07:49 PM
Re: Generate password with only letters and numbers?

Some strange behavior with this script modified just a bit. Riddle me this...

This returns 8 chars as specified:

code:
udfPWGen(8,"vfewgc000v") ?

Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"BCDFGHJKLMNPQRSTVWXYZ"
$sTerminal=$sTerminal+"bcdfghjklmnpqrstvwxyz"
$sNonTerminal="0123456789"
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd($iSeed*@monthno)
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom))+1),1))
Next
EndFunction

This also returns 8 even though I specified 9

code:
udfPWGen(9,"vfewgc000v") ?

Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"BCDFGHJKLMNPQRSTVWXYZ"
$sTerminal=$sTerminal+"bcdfghjklmnpqrstvwxyz"
$sNonTerminal="0123456789"
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd($iSeed*@monthno)
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom))+1),1))
Next
EndFunction

This returns only 9 even though 10 specified.
code:
udfPWGen(10,"vfewgc000v") ?

Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"BCDFGHJKLMNPQRSTVWXYZ"
$sTerminal=$sTerminal+"bcdfghjklmnpqrstvwxyz"
$sNonTerminal="0123456789"
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd($iSeed*@monthno)
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom))+1),1))
Next
EndFunction

I cannot replicate the error with any other input besides 'vfewgc000v', but this input certainly doesn't work right.


Richard H.Administrator
(KiX Supporter)
2003-09-03 09:42 AM
Re: Generate password with only letters and numbers?

Oops.

The problem is caused by the way I've used RND(). Normally RND(ceiling) implementations return a random number which is between 0 and ceiling-1, in other words the modulo of ceiling, or in some cases between 1 and ceiling. KiXtart returns a value between 0 and ceiling, which is a little unusual.

In the password generator UDF this would occasionally cause it to read past the end of the $sSelectFrom string, adding a blank character.

The fixed version follows:


Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"BCDFGHJKLMNPQRSTVWXYZ"
$sTerminal=$sTerminal+"bcdfghjklmnpqrstvwxyz"
$sNonTerminal="0123456789"
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd($iSeed*@monthno)
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom)-1)+1),1))
Next
EndFunction



Serves me right for not reading the manual properly.


jtokach
(Seasoned Scripter)
2003-09-03 04:23 PM
Re: Generate password with only letters and numbers?

Ahhh. Makes sense now. I would have figured that substr would have thrown and error by trying to read beyond the bounds of its string...

Richard H.Administrator
(KiX Supporter)
2004-05-07 10:38 AM
Re: Generate password with only letters and numbers?

Updated again to handle non-seeded calls better.

Code:
$i=udfpwgen(5,@TIME+"initialseedvalue")
$i=10
while $i
$i " " udfpwgen(10) ?
$i=$i-1
Loop

Function udfPWGen($iLength,Optional $sSeed)
Dim $sTerminal,$sNonTerminal,$iIndex,$iSeed

$sTerminal=$sTerminal+"BCDFGHJKLMNPQRSTVWXYZ"
$sTerminal=$sTerminal+"bcdfghjklmnpqrstvwxyz"
$sNonTerminal="0123456789"
If $sSeed<>""
For $iIndex=1 To Len($sSeed)
$iSeed=$iSeed*10+Asc(SubStr($sSeed,$iIndex,1))
Next
Srnd($iSeed)
; Discard first (not very random) value
$iIndex=Rnd(0)
EndIf
For $iIndex=1 to $iLength
$sSelectFrom=IIF($iIndex=1 OR $iIndex=$iLength,$sTerminal,$sTerminal+$sNonTerminal)
$udfPWGen=$udfPWGEn+Cstr(Substr($sSelectFrom,(Rnd(Len($sSelectFrom)-1)+1),1))
Next
EndFunction