2 Password Recovery questions!

J

Jeff

hi

asp.net 2.0

#1
How do I in the OnSendingMail method get the user email address so I knows
where to send the email?

#2
What is the code I need to use in the bodyfile for specifying where the
password should be placed in the email?

Best Regards!
 
C

Cowboy \(Gregory A. Beamer\)

#1
First, make sure you need to send the email before circumventing the
automagic stuff. If so you can use the sendingEmail to circumvent.

Make sure you include this:

e.Cancel = True

If not, you will send both yours and the one from the control. Here is a
routine I set up for test purposes (VB - normally I am C#, but it should be
easy enough to translate, if that is your desire):

Private Sub SendVerificationEmail(ByRef userName As String, ByVal
password As String, ByVal email As String)

Dim path As String = "~/emails/resetPassword.txt"
Dim reader As New StreamReader(Server.MapPath(path))


Dim fromAddress As String =
ConfigurationManager.AppSettings("ForgottenPasswordEmailAddress")
Dim toAddress As String = email
Dim subject As String = "Your Logon Information"
Dim message As String = reader.ReadToEnd()

'Yeah this sucks, but it is doing wrong otherwise
message = message.Replace("{userName}", userName)
message = message.Replace("{loginName}", userName)
message = message.Replace("{password}", password)

Dim msg As New MailMessage(fromAddress, toAddress, subject, message)

Dim smtp As New SmtpClient()
smtp.DeliveryMethod = SmtpDeliveryMethod.Network
smtp.Send(msg)

End Sub

The text in password.txt is:

Dear {userName},


Your MySite.com user name and password are :

Login Name : {loginName}
Generated Password : {password}

For security purposes, you should log in and reset your password as soon as
possible. Please log in using the above password and go to the Personal Menu
and click MyPassword. Use the above password for the old password and choose
a new password.


Thank you for using MySite.com.

You can alter this however you please.
 
J

Jeff

Thanks for that tip. On a second thought I think I will not send email when
password is being changed. However I'm thankful for that information you
gave me, because I will use it for creating email for password recovery
etc...

Yes I prefer c#

but to another problem:
When I click on the button in passwordrecovery nothing happens, below is the
markup of my passwordrecovery.
<asp:ChangePassword ID="ChangePassword1" runat="server">
<ChangePasswordTemplate>
<table style="background-color:#bbccee;">
<tr>
<td align="right">Nåværende Passord:</td>
<td><asp:TextBox ID="CurrentPassword" TextMode="Password"
runat="server"></asp:TextBox></td>
<td>
<asp:RequiredFieldValidator ID="valRequireUsername"
SetFocusOnError="true"
Display="Dynamic"
ControlToValidate="CurrentPassword" runat="server"
ErrorMessage="Nåværende passord er nødvendig"
ValidationGroup="ChangePassword1" >*</asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td align="right">Nytt Passord:</td>
<td><asp:TextBox ID="NewPassword" TextMode="Password"
runat="server"></asp:TextBox></td>
<td></td>
</tr>
<tr>
<td align="right">Bekreft Passord:</td>
<td><asp:TextBox ID="ConfirmPassword" TextMode="Password"
runat="server"></asp:TextBox></td>
<td></td>
</tr>
<tr>
<td colspan="3">
<asp:Label ID="FailureText" EnableViewState="false"
runat="server" ></asp:Label>
<asp:ImageButton ID="ChangePassword"
CommandName="Submit" ImageUrl="~/Images/Go.gif" runat="server" />
</td>

</tr>
</table>
</ChangePasswordTemplate>
</asp:ChangePassword>

any suggestions?
 
J

Jeff

Opps, that isn't passwordrecovery, but changepassword instead. I refer to
the last section in my previous post where I mention I have trouble with my
changepasword control...
 
C

Cowboy \(Gregory A. Beamer\)

It was not a spot on example, but I am glad if it helps. ;-)
 
J

Jeff

yeah, thank you. That problem is solved.

right now I'm twisting my head with another PaswordRecovery problem;
If I click on the submit button without having entered a username, no error
message is displayed.

I thought the error should be displayed in the FailureText label, but it
isn't. The only thing displayed by the RequiredFieldValidator is that "*"

<asp:TableRow>
<asp:TableCell>Brukernavn:</asp:TableCell>
<asp:TableCell><asp:TextBox ID="UserName"
runat="server"></asp:TextBox></asp:TableCell>
<asp:TableCell Width="10" >
<asp:RequiredFieldValidator ID="valRequireUsername" SetFocusOnError="true"
Display="Dynamic" ControlToValidate="UserName" runat="server"
ErrorMessage="Brukernavn er påkrevd" ValidationGroup="pwdRecovery"
>*</asp:RequiredFieldValidator>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell ColumnSpan="2" HorizontalAlign="Right">
<asp:Label ID="FailureText" runat="server"
EnableViewState="false"></asp:Label>
<asp:ImageButton ID="SubmitButton" ImageUrl="~/Images/Go.gif"
CommandName="Submit" ValidationGroup="pwdRecovery" runat="server" />
</asp:TableCell>
</asp:TableRow>

any suggetions?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top