Webforms ASP.NET身份系统重置密码 [英] Webforms ASP.NET Identity system reset password

查看:93
本文介绍了Webforms ASP.NET身份系统重置密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用Webforms在新的ASP.NET Identity系统中获取用户密码?或者如何在不知道当前密码的情况下重置密码(用户忘记了密码)?

How can I get the password of a user in the new ASP.NET Identity system using webforms? Or how can I reset without knowing the current one (user forgot password)?

推荐答案

我用这种方式重置密码并将其发送给用户

I tied this way to reset password and send it to the user

if (userId != string.Empty)
        {
            string _newPass = RandomPass();

            if (manager.HasPassword(userId))
            {
                IdentityResult ir1 = manager.RemovePassword(userId);
                if (ir1.Succeeded)
                {
                    IdentityResult ir2 = manager.AddPassword(userId, _newPass);

                    if (ir1.Succeeded && ir2.Succeeded)
                    {
                        //Send password to user via sms or email
                        Response.Redirect("~/RecoverPassword?m=ChangePwdSuccess");
                    }
                    else
                    {
                        AddErrors(ir1);
                        AddErrors(ir2);
                    }
                }
            }
        }

这篇关于Webforms ASP.NET身份系统重置密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆