asp.net-mvc - 将当前密码与数据库密码 ASP.NET MVC 与 DataAnnotations 进行比较
问题描述
如何将用户的CurrentPassword
密码与存储在数据库中的密码进行比较?
我想让我的当前密码与我的数据库密码进行比较,但我该怎么做呢?数据库密码采用 MD5 加密。
public async Task<IActionResult> ChangePassword(ChangePasswordVM changePasswordVM, string returnUrl = null)
{
LeaveUser _User = await _userManager.GetUserAsync(User);
if (ModelState.IsValid)
{
var result = await _userManager.ChangePasswordAsync(_User, changePasswordVM.CurrentPassword, changePasswordVM.ConfirmNewPassword);
if (result.Succeeded)
{
if (returnUrl == null)
return RedirectToAction("Index", "Home");
else
return LocalRedirect(returnUrl);
}
ModelState.AddModelError("", "Invalid Password Change Attempt.");
}
return View();
}
[Required(ErrorMessage = "Please enter Current Password")]
[DataType(DataType.Password)]
[Display(Name = "Current Password : ")]
public string CurrentPassword { get; set; }
[Required(ErrorMessage = "Please enter New Password")]
[MinLength(8), MaxLength(20)]
[DataType(DataType.Password)]
[Display(Name = "New Password : ")]
public string NewPassword { get; set; }
[Required(ErrorMessage = "Please confirm Password")]
[MinLength(8), MaxLength(20)]
[DataType(DataType.Password)]
[Compare("NewPassword", ErrorMessage = "The password does not match the confirmation password.")]
[Display(Name = "Confirm New Password : ")]
public string ConfirmNewPassword { get; set; }
解决方案
推荐阅读
- breakpoints - 不工作的顺风断点
- javascript - 标题相对于图片的偏移量
- python - Python Pandas pivot_table:意外结果
- c# - C# - .net 核心 DateTime 转换为 UTC 分钟偏移量
- java - 当@Sendto失败时,rabbitMQ与spring boot amqp连接无限错误
- android - 在 Android 的 Web 视图中显示 base64 字符串 PDF
- javascript - 从反应类到钩子的变化
- filtering - 将新筛选器添加到 Tableau 上的现有仪表板
- python - 运行多个脚本并处理 Docker
- python-3.x - 如何检测图像中记录的边界?