【问题标题】:How to save previous password to be able to change current one如何保存以前的密码以更改当前密码
【发布时间】:2015-12-20 11:23:58
【问题描述】:

我正在使用 Intranet,我将创建帐户(通过表单身份验证)与创建 Employee 融合在一起 - 创建 Employee 会创建一个帐户(简单)。

但问题是,我希望当我在 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")字符串中的密码对其进行了测试,它有效,我需要的只是一种保存前一个密码的方法。

有什么想法可以实现吗?

【问题讨论】:

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


    【解决方案1】:

    您是否尝试过将旧密码与新密码连接起来? 我的意思是:

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

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

    NEWPASS====OLDPASS
    

    祝你好运!

    【讨论】:

    • 问题是我找不到保存 oldpwd 的方法。它等于objToEdit.Password,它采用当前(因此已更改)密码值。
    • 好吧。有一次您可以访问旧密码和新密码吗?所以此时,把新密码=oldpassword."====".newpassword;
    猜你喜欢
    • 2021-04-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-25
    • 1970-01-01
    相关资源
    最近更新 更多