Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing info

Status
Not open for further replies.

Ragol1

Programmer
Oct 25, 2001
315
0
0
US
I use this below code to create a random password and I can get the password to disply on the screen.
I want to pass this info on to a database and ASP mail which already is set up but its not passing the password data over

<%
Dim X
Response.Write &quot;<HTML>&quot; & vbCrLf
Response.Write &quot;<HEAD>&quot; & vbCrLf
Response.Write &quot;<TITLE> </TITLE>&quot; & vbCrLf
Response.Write &quot;</HEAD>&quot; & vbCrLf
Response.Write &quot;<BODY>&quot; & vbCrLf
Response.Write &quot;<FONT FACE=COURIER>&quot; & vbCrLf
Response.Write RandomPW(7) & &quot;<br>&quot; & vbCrLf
'Set Length to 0 for random password Length
'Response.Write RandomPW(0) & &quot;<br>&quot; & vbCrLf


Response.Write &quot;</FONT>&quot; & vbCrLf
Response.Write &quot;</BODY>&quot; & vbCrLf
Response.Write &quot;</HTML>&quot; & vbCrLf



Function RandomPW(myLength)
'These constant are the minimum and maximum length for random
'length passwords. Adjust these values to your needs.
Const minLength = 6
Const maxLength = 20

Dim X, Y, strPW

If myLength = 0 Then
Randomize
myLength = Int((maxLength * Rnd) + minLength)
End If


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 try this and it doesnt grab the RandomPW or strPW what do i need to do
<%
Set mail = Server.CreateObject(&quot;Persits.Mailsender&quot;)
Mail.Host = &quot;my mail server&quot;



strUserID = request.form(&quot;UserID&quot;)
strPassword = RandomPW
strEmail = request.form(&quot;Email&quot;)


Mail.From = strEmail
Mail.FromName = strUserID
Mail.AddBCC &quot;email&quot;
Mail.AddBCC &quot;email&quot;
Mail.AddAddress strEmail
Mail.AddReplyTo strEmail
'Mail.AddAttachment &quot;c:\any file&quot;
strBodyHeader = &quot;&quot; & chr(13) & chr(10) & chr(13) & chr(10)
strBodyHeader = strBodyHeader & &quot;This is your UserID : &quot; & strUserID & chr(13) & chr(10)
strBodyHeader = strBodyHeader & &quot;This is your Password : &quot; & strPassword & chr(13) & chr(10)
strBody = strBodyHeader & strBody
Mail.Subject = &quot;&quot;
Mail.body = strBody
'Mail.Body = &quot;Dear Fan:&quot; & Chr(13) & Chr(10) & &quot;Thank you for your business.&quot;


On Error Resume Next
Mail.Send
If Err <> 0 Then
Response.Write &quot;Error encountered: &quot; & Err.Description
End If
%>
 
do you get any errors?

because if it gets to:

strPassword = RandomPW

i would think it would say something about invalid # of parameters.... because you specify (myLength) parameter, but don't use it when you call the function.
so if you're not getting an error there, then it seems it's not even getting to that statement, means you need to tshoot above that point.
if you are getting an error about that, then you need to specify (myLength):

strPassword = RandomPW(0)
 
At the beginning where you've typed:

Response.Write RandomPW(7) & &quot;<br>&quot; & vbCrLf

Instead you should assign this password to a variable at this point so that it remains constant throughout the execution of the script:

strPassword=RandomPW(7)

Then display it using:

Response.Write strPassword & &quot;<br>&quot; & vbCrLf

And use it in your email text as before:

strBodyHeader = strBodyHeader & &quot;This is your Password : &quot; & strPassword & chr(13) & chr(10)

Previously the password displayed on screen, and the password sent by email would have been different.




 
yes your right when I type strPassword = RandomPW(7) it works but my problem now is that i use it twice once to add info to a database then to send user an email and it is running twice and selecting 2 different random passwords.
Is thier any way that once ive used it to add to the database that I can keep what I have used to use it in the email part.


Nick
 
as davyfitz said in his response, put

strPassword=RandomPW(7)

above all of your response.write statements at the top, then throughout the rest of your code(except for the RandomPW function), use strPassword for the password, that's where the password is stored.

ex.

Response.Write strPassword & &quot;<br>&quot; & vbCrLf



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top