如何保存以前的密码才能更改当前密码

时间:2015-09-23 08:28:52

标签: c# asp.net-mvc forms-authentication

我正在内部网上工作,我将创建帐户(通过表单身份验证)与创建员工融合在一起 - 创建一个员工创建一个帐户(简单)。

但是问题就在这里,我希望当我在Employee部分更改密码时,它也会以auth格式更改密码。一部分。

这是我到目前为止所拥有的:

[HttpPost]
public ActionResult Edit(Employee objToEdit, FormCollection form)
{
    //string oldpwd = objToEdit.Password;            
    IEnumerable<SelectListItem> CompanyList = _service.ListCompany();
    ViewBag.CompanyList = CompanyList;

    IEnumerable<SelectListItem> SupervisorList = _service.ListSupervisor();
    ViewBag.SupervisorList = SupervisorList;

    objToEdit.UpdatedDate = System.DateTime.Now;
    objToEdit.CompanyId = int.Parse(form["CompanyId"]);
    objToEdit.Supervisor = form["Supervisor"];

    if (_service.Edit(objToEdit))
    {
        //bool changePasswordSucceeded; // Find a way to store old and new pwd
        //try
        //{
        //    changePasswordSucceeded = WebSecurity.ChangePassword(User.Identity.Name, oldpwd, objToEdit.Password);
        //}
        //catch (Exception)
        //{
        //    changePasswordSucceeded = false;
        //}

        //if (changePasswordSucceeded)
        //{
        //    return RedirectToAction("Index", new { Message = CRAWebSiteMVC.Controllers.AccountController.ManageMessageId.ChangePasswordSuccess });
        //}
        //else
        //{
        //    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
        //}
        return new RedirectResult(Url.Action("Index"));
    }
    return View();
}

评论中的所有内容都来自表单身份验证管理功能,我想使用旧密码并使用新密码进行更改,但我似乎无法找到保存旧密码的方法。

使用直接写在oldpwd(例如oldpwd = "mypwd")字符串中的密码对其进行测试并且它有效,我只需要保存前一个。

有关如何实现这一目标的任何想法?

1 个答案:

答案 0 :(得分:0)

您是否尝试将旧pwd连接到新的pwd? 我的意思是:

oldpwd = "mypwd"."====".oldpwd;

使用这个oldpwd变量将如下所示:

NEWPASS====OLDPASS

祝你好运!