使用电子邮件而不是用户名恢复密码

发布于 2024-07-23 08:37:03 字数 880 浏览 3 评论 0原文

我宁愿让他们输入电子邮件地址并重置密码并将其发送给他们,而不是强迫用户记住用户名。

我在会员提供程序下使用 ASP .Net PasswordRecovery 控件。

现在系统工作正常,它重置密码并发送给用户。 然而,我发现许多用户忘记了他们的用户名。 显然,我在发给他们的电子邮件中包含了用户名。

理想情况下,我会完全放弃用户名,但不幸的是我已经有用户的用户名不是电子邮件地址。

那么,如何轻松更改我的PasswordRecovery 控件以询问用户的电子邮件地址并将重置密码和用户名发送到该地址?

我尝试添加

UserNameLabelText="Email:" OnVerifyingUser="PasswordRecovery1_VerifyingUser"

到 asp:PasswordRecovery 和

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

关联的 .cs 文件中,但控件无法编译并出现错误

CS0123:“PasswordRecovery1_VerifyingUser”匹配没有重载 委托“System.Web.UI.WebControls.LoginCancelEventHandler”

我不明白的

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

给妤﹃绝世温柔 2024-07-30 08:37:03

您可以实现PasswordRecovery.VerifyingUser 事件的处理程序以允许用户提供用户名或密码。

protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
{
    PasswordRecovery passRecovery = (PasswordRecovery)sender;

    if (Membership.FindUsersByName(passRecovery.UserName).Count == 0)
    {
        // There is no matching user name.  Check to see if a known email address
        // was entered.  If so use the user name corresponding to the email address.
        string user = Membership.GetUserNameByEmail(passRecovery.UserName);
        if (user != null)
            passRecovery.UserName = user;
    }
}

You can implement a handler of the PasswordRecovery.VerifyingUser event to allow the user to provide either a user name or a password.

protected void PasswordRecovery1_VerifyingUser(object sender, LoginCancelEventArgs e)
{
    PasswordRecovery passRecovery = (PasswordRecovery)sender;

    if (Membership.FindUsersByName(passRecovery.UserName).Count == 0)
    {
        // There is no matching user name.  Check to see if a known email address
        // was entered.  If so use the user name corresponding to the email address.
        string user = Membership.GetUserNameByEmail(passRecovery.UserName);
        if (user != null)
            passRecovery.UserName = user;
    }
}
ぽ尐不点ル 2024-07-30 08:37:03

因此,如果用户不知道他们的用户名,他们会提供他们的电子邮件,然后您使用 FindUsersByEmail 或 GetUsernameByEmail。

如果他们不知道自己的电子邮件地址,他们会提供用户名,然后您使用 FindUsersByName。

正如凯德指出的那样 - 从你的帖子中你的问题并不是很明显。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文