Trying to implement asp.net passwordrecovery control.
I want to catch newly generated password before sending to user and add some custom logic to it and then send the mail. there is only one event sendingmail event.
How can I catch it ?
Trying to implement asp.net passwordrecovery control.
I want to catch newly generated password before sending to user and add some custom logic to it and then send the mail. there is only one event sendingmail event.
How can I catch it ?
The ValidatingPassword event is raised when the CreateUser method, the ChangePassword method, or the ResetPassword method of a membership provider is called.
What "custom logic" do you want to implement?
If you want to modify the email that is sent, then hooking into the SendingMail event on the control is the way to go.
Use this event to do any special processing required before sending the e-mail message, such as setting MailMessage properties.
This will give you access to the MailDefinition object that enables you to supply different body copy etc. The MailDefinition documents list the substitutions that will occur as well (this can also be created declaratively):
<asp:PasswordRecovery ID="PasswordRecovery1" Runat="server"
SubmitButtonText="Get Password" SubmitButtonType="Link">
<MailDefinition From="[email protected]"
Subject="Your new password"
BodyFileName="PasswordMail.txt" />
</asp:PasswordRecovery>
The new password would be stored in the database at this stage, so you could modify it there in this event prior to sending the email - have you tried that?
You could handle the SendingMail event, generate a new password using ResetPassword, and then update the body of the email with your new password and whatever else you wanted to put in there.
protected void PasswordRecovery1_SendingMail(object sender, MailMessageEventArgs e)
{
// grab the user.
MembershipUser mu = Membership.GetUser(PasswordRecovery1.UserName);
if (mu != null)
{
// reset the password.
string newPass = mu.ResetPassword();
// switch out the body of the email.
e.Message.Body = string.Format("New Password: {0}\n", newPass);
}
}
Are you planning on storing the generated password somewhere, as the phrasing of your questions suggests you want to be able to read it and do something with it?