📜  强制用户在提交表单之前输入密码 asp.net core - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:41.156000             🧑  作者: Mango

代码示例1
var user = await UserManager.FindByIdAsync(User.Identity.GetUserId());
var verifyPassword = UserManager.PasswordHasher.VerifyHashedPassword(user.PasswordHash, password);
if (verifyPassword == PasswordVerificationResult.Failed)
{
    ModelState.AddModelError("", "Password incorrect.");
    // If password is incorrect, ModelState will be invalid now
}

if (ModelState.IsValid)
{
    // save posted data
}