Forums

ASP

This topic is locked

Sending random password

Posted 10 Mar 2002 05:48:23
1
has voted
10 Mar 2002 05:48:23 Jaime Romo posted:
hello i have a problem im using this code to generate a random password,
how can i send the password to an email adress im using aspmail, aspemail or cdonts
and i also whant to insert it on a database
thanks a lot
here is the code
<%
Function gen_key(digits)

dim char_array(50)

char_array(0) = "0"
char_array(1) = "1"
char_array(2) = "2"
char_array(3) = "3"
char_array(4) = "4"
char_array(5) = "5"
char_array(6) = "6"
char_array(7) = "7"
char_array(8) = "8"
char_array(9) = "9"
char_array(10) = "A"
char_array(11) = "B"
char_array(12) = "C"
char_array(13) = "D"
char_array(14) = "E"
char_array(15) = "F"
char_array(16) = "G"
char_array(17) = "H"
char_array(18) = "I"
char_array(19) = "J"
char_array(20) = "K"
char_array(21) = "L"
char_array(22) = "M"
char_array(23) = "N"
char_array(24) = "O"
char_array(25) = "P"
char_array(26) = "Q"
char_array(27) = "R"
char_array(28) = "S"
char_array(29) = "T"
char_array(30) = "U"
char_array(31) = "V"
char_array(32) = "W"
char_array(33) = "X"
char_array(34) = "Y"
char_array(35) = "Z"

Randomize

do while len(output) < digits
num = char_array(Int((35 - 0 + 1) * Rnd + 0))
output = output + num
loop
gen_key = output
End Function

response.write "<pre>" & gen_key(15) & "</pre>" & vbcrlf

%>

Visit my home page
www.cancuncoral.com

Replies

Replied 05 Apr 2002 15:30:51
05 Apr 2002 15:30:51 martin Scullion replied:
What exactly is the problem, the code seems ok to me I have run it in VB6 with no problems
Replied 06 Apr 2002 18:08:48
06 Apr 2002 18:08:48 Hank Tan-Tenn replied:
I am curious to know if there's an advantage using the array. I suppose you could easily leave out or add other characters?

I have the following fairly mundane function. The weird part is I decided to use the hyphen, which sometimes can occur at the beginning or end of the string:

<pre id=code><font face=courier size=2 id=code>
&lt;%
Function RandomString(bytLength)
Dim bytRandchar, strString

'Generate the password string
Do Until Len(strString) = bytLength
Randomize
bytRandchar = Int(75*Rnd) + 48
If (bytRandchar &gt; 64 AND bytRandchar &lt; 91) OR (bytRandchar &gt; 96 AND bytRandchar &lt; 123) OR (bytRandchar &gt; 47 AND bytRandchar &lt; 58) Then
strString = strString & Chr(bytRandchar)
Else
strString = strString & "-"
End If
Loop

RandomString = strString
End Function
%&gt;
</font id=code></pre id=code>

Edited by - akc on 06 Apr 2002 18:22:24

Reply to this topic