Webforms ASP.NET Identity系统重置密码

时间:2014-03-11 06:52:16

标签: webforms passwords reset identity

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

1 个答案:

答案 0 :(得分:1)

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

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);
                    }
                }
            }
        }