PDA

View Full Version : Random Passwords



LittleMan
05-05-2002, 02:36 PM
Right now I'm using the following function to generate passwords:

Function RandomPW(myLength)

Dim X, Y, strPW

For X = 1 To myLength
'Randomize the type of this character
Y = Int((3 * Rnd) + 1) '(1) Numeric, (2) Uppercase, (3) Lowercase

Select Case Y
Case 1
'Numeric character
Randomize
strPW = strPW & CHR(Int((9 * Rnd) + 48))
Case 2
'Uppercase character
Randomize
strPW = strPW & CHR(Int((25 * Rnd) + 65))
Case 3
'Lowercase character
Randomize
strPW = strPW & CHR(Int((25 * Rnd) + 97))
End Select
Next

RandomPW = strPW

End Function

I then store the function later with something like this:

strPassword = RandomPW(8)

And then I can call it throughout an email by using & strPassword &

The problem is that each time I write the & strPassword & it's generating a new password !!! How do I save the origional value so it's only calling the function once.

Thanks,
-Ryan.

no_mac_jack
05-05-2002, 05:22 PM
Well, I haven't done any ASP for several months, but it looks right to me. Maybe I can try it later on the other computer.

In the mean time, I found a list of other random password generators (http://www.aspin.com/home/tutorial/usermanage/randompa).


~no_mac_jack

LittleMan
05-05-2002, 08:48 PM
I think the code is all ok...

I just need a way to store the FIRST random password that get's created because each time I'm calling strPassword it's creating a new random password ?!?

no_mac_jack
05-05-2002, 10:58 PM
That's what I mean...I don't think the code should do that. In all the different languages I've tried, I don't remember a single one re-calling a function when you're defining a value like that. Once strPassword is set to the result of RandomPW(8), it should be a string and shouldn't call the function again unless you tell it to.

It's been a long day I'll take another look tomorrow. Anyone else see anything?

~no_mac_jack

awasson
05-05-2002, 11:19 PM
Hey guys,

I'd create an instance of the FSO File System Object and write the password to a text file or..... save it to a database for further retrieval along with some sort of other information that is intended to be used with the password.

Random ASP functions are somewhat random whenever you call them.... ie whenever the page is called..... you could also save the results to a session variable but that dissapears at the end of the session, so a database or text file is the only way.

Of course you could always create an ASPMail object and fire off a copy for yourself, but then it's up to you to store retieve and administrate the info, so for automation we are back to the FSO or DB.

Andrew