Webforms ASP.NET Identity system reset password

风格不统一 提交于 2019-12-11 10:04:01

问题


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)?


回答1:


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


来源:https://stackoverflow.com/questions/22318434/webforms-asp-net-identity-system-reset-password

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!