如何不使用 ASP.Net 会员安全问题和答案进行自定义密码恢复?

发布于 2024-07-21 05:20:44 字数 367 浏览 7 评论 0原文

我不想拥有 ASP.Net 会员提供商提供的安全问题和答案功能,但我确实想启用丢失/忘记密码页面。

在此页面上,用户输入他/她的电子邮件地址,如果用户注册了,则通过发送到该注册电子邮件地址的链接重置密码,电子邮件将发送到该地址

我已创建自定义表格为了跟踪此类请求,分配给请求的随机密钥以及请求的到期日期。 然而,在编写实际重置密码的代码时,我意识到似乎没有一种方法可以执行类似 ResetPassword(email, newPassword) 的操作,而无需使用安全问答位(我没有)。

有没有什么方法可以通过内置的会员功能简单地重置用户密码?

如果没有,我需要如何完成这件事?

预先感谢您提供的任何帮助。 -日产

I don't want to have the security question and answer feature that ASP.Net Membership Provider gives, but I DO want to enable a lost/forgotten password page.

This page would be where a user would enter his/her email address and an email would be sent to that address if the user was registered for them to reset their password via a link sent to that registered email address

I've created the custom table to track such requests, the random key assigned to the request as well as an expiry date on the request. However in writing the code to actually reset the password, I realised that there doesn't seem to be a method that does something like ResetPassword(email, newPassword) without needing to use the Security Q&A bit (which I don't have).

Is there any way to simply reset a user's password via a built in Membership function?

If not, how would I need to get this done?

Thanks in advance for any help given.
-Nissan

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

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

发布评论

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

评论(2

仅此而已 2024-07-28 05:20:44

我最终做了以下事情,

public string ResetPassword(string email)
        {
            var m_userName = Membership.GetUserNameByEmail(email);
            var m_user = Membership.GetUser(m_userName);
            return m_user.ResetPassword();
        }

然后我添加了一个新方法来使用该值来更改密码

public bool ChangeLostPassword(string email, string newPassword)
    {
        var resetPassword = ResetPassword(email);
        var currentUser = Membership.GetUser(Membership.GetUserNameByEmail(email), true);
        return currentUser.ChangePassword(resetPassword, newPassword);

    }

What I ended up doing was the following

public string ResetPassword(string email)
        {
            var m_userName = Membership.GetUserNameByEmail(email);
            var m_user = Membership.GetUser(m_userName);
            return m_user.ResetPassword();
        }

then I added a new method to use this value to change the password

public bool ChangeLostPassword(string email, string newPassword)
    {
        var resetPassword = ResetPassword(email);
        var currentUser = Membership.GetUser(Membership.GetUserNameByEmail(email), true);
        return currentUser.ChangePassword(resetPassword, newPassword);

    }
时光礼记 2024-07-28 05:20:44

为什么不在 web.config 中更改此选项?

         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"

<membership>
   <providers>
      <clear/>
      <add name="AspNetSqlMembershipProvider" ...
      ..........

Why don't you change this options in web.config?

         enablePasswordRetrieval="false"
         enablePasswordReset="true"
         requiresQuestionAndAnswer="false"

in

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