【发布时间】: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