【发布时间】:2020-08-20 07:00:39
【问题描述】:
在我的控制器中,我想计算错误登录尝试的次数。
else
{
// Increment counter by 1
// check if counter == 3
// ban user
logonAttempt++;
if (logonAttempt >= MAX_LOGON_ATTEMPT)
{
ModelState.AddModelError("", "This account has been locked. Please contact the help desk for further support.");
} else
{
ModelState.AddModelError("", "You have entered an invalid username or password.");
}
}
每次用户点击“提交”并且代码进入这个 else 语句时,logonAttempt 重置为 0。
有没有办法阻止它重置?用户会话?
【问题讨论】:
-
您是否将 loginAttempt 变量存储回会话中?
-
或者你真的在使用会话吗?
-
我相信我是。如果用户登录成功,等待 HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal);
-
您需要使用 HttpContext.Session 来存储多个请求的任何值,但@aepelman 的帖子对于身份验证是正确的
标签: c# asp.net asp.net-core-mvc counter