Print Page | Close Window

Emailing a randomly generated Password

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: ASP.NET Discussion
Forum Description: Discussion and chat on ASP.NET related topics.
URL: https://forums.webwiz.net/forum_posts.asp?TID=7366
Printed Date: 29 March 2026 at 3:40pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Emailing a randomly generated Password
Posted By: IrishNewbie
Subject: Emailing a randomly generated Password
Date Posted: 18 November 2003 at 10:12am

Guys,

I have my site working so that when someone enters there ID and hits Login a random 10 char password is generated and its stored with their id in the DB.  I also have email from a page StdMail.aspx working but i have the adress of the recipient hard coded in.  What Im trying to do is pass the UserID from Login.aspx to StdMail.aspx, Open a connection to the DB, retrieve the Email Address of the User and then email them their new password. 

My Code looks like:

<code>

<%@ Page Language ="VB" Debug="True" %>
<%@ Import Namespace="System.Web.Mail" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>

<html>
<body>
 <script runat = server>


     Dim UserID As Integer

     UserID = Request.Querystring("txtUserID")

 
 Response.Write(UserID)

  Dim aConnection As OleDbConnection = New OleDbConnection
         Dim aConnectionString As String
         Dim aQuery As String
  Dim UserEmail As String
         aConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\DB\records.mdb"
         aConnection.ConnectionString = aConnectionString
         Dim aCommand As OleDbCommand = New OleDbCommand
         aConnection.Open()
         aQuery = "Select EmailName From Students Where UserID = "& UserID &""
         aCommand.Connection = aConnection
         aCommand = New OleDbCommand(aQuery, aConnection)
         aCommand.ExecuteNonQuery()
 


 


     
</script>
 <%
 'Send an email address with product information
   
   Dim BodyFormat As String = MailFormat.Html
   Dim EmailTo As String = mailto:someone@somewhere.com - someone@somewhere.com
   Dim EmailFrom As String = " mailto:CSIS@hotmail.com - CSIS@hotmail.com "
  Dim EmailBody As String
 Dim EmailSubject As String = "Password For Login"

 EmailBody = "Just a Test Email!!!"


   'Send the message
 SmtpMail.smtpserver = "gabriel.ul.ie"
  SmtpMail.Send(EmailFrom, EmailTo, EmailSubject, EmailBody)

   'Display notification of mail being sent
 Response.Write(UserID)

  Response.Write("<font color=red><b>Your Password Has been sent to you! Thank you!</b></font>")
 %>
</body>
</html>

</code>

I dont know what to put into EMailTo in order to reference it to the EMailName from the DB. Anyone shed any light on this???




Replies:
Posted By: MorningZ
Date Posted: 18 November 2003 at 10:32am

will you pleeeeeeeeeeeeeease http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2.shtml - read this 4guys article ....  you'd get so much help if you had a clue of what commands to use

"aCommand.ExecuteNonQuery()"

does not return data.. so you cannot ask the database "give me this information" and use the ExecuteNonQuery() method because it returns nothing but how many rows got affected

seriously man, you need to do some research



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 18 November 2003 at 12:33pm
I reckon if we copy and paste the last few topics we will get a working login system


Posted By: IrishNewbie
Date Posted: 18 November 2003 at 2:32pm
Ok MorningZ, I've been reading that tutorial you suggested, I realise that the ExecuteScalar() command is what i should be using.  If I say something Like Dim EmailTo As String = aCommand.ExecuteScalar() after I use the select statement, how do i use the variable EmailTo in the body of my html page within asp tags?? I keep getting the error that it isnt declared.


Posted By: Mart
Date Posted: 18 November 2003 at 2:44pm

As far as i can see you don't have a datareader, http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2.shtml - http://www.4guysfromrolla.com/webtech/chapters/ASPNET/ch06.2 .shtml  for more info.

Then you would use Dim EmailTo As String  = dr.item("email") where dr is your datareader and email is  your email address field.



Posted By: IrishNewbie
Date Posted: 18 November 2003 at 2:48pm
But if its only one variable being returned cant i just use ExecuteScalar()????


Posted By: Mart
Date Posted: 18 November 2003 at 3:04pm

You need to use a datareader or the other one (i forgot what its called) to read form the db! I havent used ExecuteScalar() so i don't know what it does. I do know you can just use ExecuteReader() even if its one record.

Remember that when using a DataReader you must call Read() before obtaining data.



Posted By: IrishNewbie
Date Posted: 18 November 2003 at 3:41pm

Dim aReader As OleDbDataReader
Line 25: aReader = aCommand.ExecuteReader()
 can you tell me mart what this means

Data type mismatch in criteria expression

 

 

 



Posted By: Diep-Vriezer
Date Posted: 19 November 2003 at 6:35am

Not really..

By the way, you can also use the objEmail for creating an e-mail message.

Dim objEmail As New MailMessage

With objEmail

  .To = "..@.."
  .Body = "..2@.."

End With

SmtpMail.Send(objEmail)



-------------
Gone..


Posted By: Mart
Date Posted: 19 November 2003 at 9:32am
Its an SQL statement error, If your selecting a number dont use 'quotes' if that still doesnt work post in your SQL statement or go to http://www.w3schools.com/sql - www.w3schools.com/sql


Posted By: IrishNewbie
Date Posted: 19 November 2003 at 12:12pm

Ok Ive gotten rid of that error, my problem is not knowing how to use a variable which is received from the statement, outside of where i get it, if i want to use it in the html part of my page how do i do it.



Posted By: Mart
Date Posted: 19 November 2003 at 12:49pm
Just use a simple label!!! you really need to learn the basics.


Posted By: MorningZ
Date Posted: 19 November 2003 at 1:39pm
<script runat="server">
Sub Page_Load( obj as Object, e as EventArgs )
     Dim I_am_a_variable As String
     I_am_a_variable = "It's a Fuster Cluck"
     clue.Text = I_am_a_variable
End Sub
</script>
<html>
<body>
Survey says:<br />
<asp:label id="clue" runat="server"/>
</body>
</html>

-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: IrishNewbie
Date Posted: 19 November 2003 at 3:17pm
not what i meant, i want to use the EmailName returned by the statement and bring it down to where im sending the email, it wont let me just say "EmailTo" as it says that it isnt declared. do ye know what i mean?


Posted By: MorningZ
Date Posted: 19 November 2003 at 7:13pm

now i wrote this off the top of my head, but http://www.morningz.com/sections/playground/files/code/emailpass.txt - here's the code i would write if i was doing something like what you are trying to do

i wrote it in Notepad on my desktop and didn't check if it works, so if i have a typo somewhere or something..... tough, lol



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: IrishNewbie
Date Posted: 20 November 2003 at 7:47am

Thanks MorningZ, ive tried it and i reckon theres a problem getting the txtUserID from the Login page, Should i put it as an Int on the Email page if its a Int on the Login page?? Ive tried this and no success, its telling me everytime that there was a problem sending the email,  this is the Redirect section of my login page,

If Login (txtUserID.Text) Then   
      FormsAuthentication.RedirectFromLoginPage ("txtUserID.Text", False)
 
  Else
      ' Invalid credentials supplied, display message
      lblMessage.Text = "Invalid login credentials"
  End If

 



Posted By: MorningZ
Date Posted: 20 November 2003 at 8:42am

i have absolutely zero idea what you are asking or what that if.. then.. else statement above

i can tell that you still have absolutely no clue what is going on though...... amazing after 3 or 4 threads of this.......



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 20 November 2003 at 2:14pm
Is this a login page or a email form, ive lost the plot here


Posted By: IrishNewbie
Date Posted: 21 November 2003 at 3:35am
Its a login page, which take the user id and if valid, moves to the EmailPword page, i want to know how to pass the txtUserId password from the login page to the Email page.


Posted By: MorningZ
Date Posted: 21 November 2003 at 8:34am

Originally posted by IrishNewbie IrishNewbie wrote:

Its a login page, which take the user id and if valid, moves to the EmailPword page, i want to know how to pass the txtUserId password from the login page to the Email page.

:: sigh ::
from your very original post:
"UserID = Request.Querystring("txtUserID")"

so where is this page looking for the "txtUserID" ???
why is it so impossible for you to see this is coming from the "QueryString"

your lack of "getting it" is starting to get annoying and this thread is waaaaaaaaaaaaaaaaaaaaaaaaay too long for this



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: IrishNewbie
Date Posted: 21 November 2003 at 8:52am
fvck off you smart cvnt, this board wont take off if you sit there acting the knob everytime a new user posts a message.  You are plain and simple a sneering cvnt


Posted By: MorningZ
Date Posted: 21 November 2003 at 9:18am

You seem to not grasp the fact that:
- You have no idea what to do with SQL (not something .NET related)
- You have no idea what a QueryString parameter is (not something .NET related)
- You have no idea of the difference of ASP 3.0 and ASP.NET, yes, they both say "ASP" there in the language, but they are totally different languages.....

the 20 mins i took out of my time yesterday at work to write that code for you did exactly what you wanted it to do, except that the page calling it had to feed "txtUserID" in the querystring.....

That seemed to make no sense to you, and this is super super basic things to understand, you are too far over your head..... you need to see that.....  and its not stuff thats hard to learn, but you have to "get it" at certain places...

i could give a "fvck" what you think of me, i am sorry you don't that that previously in this thread (or in other threads) i have directed you on where to get help, read up on stuff, and understand what the heck was going on with code you are trying to do.....  you could take it or leave it



-------------
Contribute to the working anarchy we fondly call the Internet


Posted By: Mart
Date Posted: 21 November 2003 at 9:34am

Originally posted by IrishNewbie IrishNewbie wrote:

fvck off you smart cvnt, this board wont take off if you sit there acting the knob everytime a new user posts a message.  You are plain and simple a sneering cvnt

I think you are very ungrateful. MZ has helped you and just told you to learn the basics. If someone said that to me after i helped them i would be offended and probably aska modertor to take action. If you dont like what were saying telling us the 'fvck' off isnt going to do anything but offend people. And i think its you who is the knob because you can't take innocent advice. This is the second time you have lashed out at him for helping you, you seriously need some anger management.




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net