R – PasswordRecovery using email instead of UserName

asp.netasp.net-membershipemailpasswords

Rather than forcing users to remember a UserName, I would rather have them enter their email address and have the password reset and sent to them.

I am using ASP .Net PasswordRecovery control under the membership provider.

Right now the system works fine, it resets the password and sends to the user. However, I find that many users forget their UserName. Obviously, I include the UserName in the email to them.

Ideally, I would dispense with usernames completely, but unfortunately I already have users with UserNames that are not email addresses.

So, how can I easily change my PasswordRecovery control to ask for the user's email address and send the reset password, and UserName to that address?

I tried adding

UserNameLabelText="Email:" OnVerifyingUser="PasswordRecovery1_VerifyingUser"

to the asp:PasswordRecovery, and

protected void PasswordRecovery1_VerifyingUser(
    object sender
  , MailMessageEventArgs e)
{ PasswordRecovery1.UserName = 
System.Web.Security.Membership.GetUserNameByEmai(PasswordRecovery1.UserName); } 

in the associated .cs file, but the control fails to compile with an error

CS0123: No overload for 'PasswordRecovery1_VerifyingUser' matches
delegate 'System.Web.UI.WebControls.LoginCancelEventHandler'

which I do not understand

Best Answer

So if the user doesn't know their username, they provide their email and you use FindUsersByEmail or GetUsernameByEmail.

If they don't know their email address, they provide their username and you use FindUsersByName.

As Cade pointed out - your question isn't really obvious from your post.