【发布时间】:2019-05-19 03:26:20
【问题描述】:
我在 Visual Studio 2017 asp.net 核心中使用默认的个人用户帐户模板和我自己的自定义用户表。 User 表有一个Password,LoginModel 有一个Password。我一直在关注here,为AccountController 中的Login。
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public virtual async Task<IActionResult> Login(LoginModel model,
string returnUrl)
{
if (ModelState.IsValid)
{
var user = _context.Users.FirstOrDefault(u => u.Email == model.Email);
var claims = new List<Claim>
{
new Claim(ClaimTypes.Email, user.Email)
};
var identity = new ClaimsIdentity(claims);
var principal = new ClaimsPrincipal(identity);
await _httpContext.Authentication.SignInAsync
(CookieAuthenticationDefaults.AuthenticationScheme,
principal, new AuthenticationProperties
{
IsPersistent = model.RememberMe,
ExpiresUtc = DateTime.UtcNow.AddYears(1)
});
return RedirectToRoute("HomePage");
}
return View(model);
}
当我运行代码时,如果我输入错误的电子邮件会抛出错误,但我可以输入任何我想要的密码并且它会成功。我如何输入密码以确保它是正确的密码?
【问题讨论】:
标签: c# asp.net-core cookies