Hello,
I work on web application in ASP.Net MVC 4.8.
In order to add a block after 4 wrong password and/or login attempts. I wanted to modify Login Action.
We don't want to use aspNet Identity because we didn't want to add a column on the database side.
I need a solution using session/cache or variable store count.
Thanks in advance.
[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public async Task<ActionResult> Login(LoginViewModel model, string returnUrl)
{
if (!ModelState.IsValid)
{
return View(model);
}
var result = await SignInManager.PasswordSignInAsync(model.UserName, model.Password, model.RememberMe, shouldLockout: false);
switch (result)
{
case SignInStatus.Success:
var user = await UserManager.FindByNameAsync(model.UserName);
HttpCookie partnerInfo = new HttpCookie("User#" + user.Id);
partnerInfo["FullName"] = user.FullName;
Response.Cookies.Add(partnerInfo);
return RedirectToLocal(returnUrl);
case SignInStatus.LockedOut:
ModelState.AddModelError("", "Account Blocked. Try after some time.");
return View("model");
case SignInStatus.RequiresVerification:
return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
case SignInStatus.Failure:
default:
ModelState.AddModelError("", "Invalid login attempt.");
}
model.NotConnect = true;
return View(model);
}