ahmed salah

ahmed salah

  • 937
  • 490
  • 30.3k

How to make maximum failed login attempt for user to 3 time only after

Dec 1 2022 11:31 PM

I work on web application asp.net core 5 i can't modify action login

to accept 3 login attempt failed only .

if he try with wrong password or wrong email account after that then block it .

I using user identity login

what I try
 

public async Task<IActionResult> Login(LoginVM loginVM)
{
    if (!ModelState.IsValid) return View(loginVM);

    var user = await _userManager.FindByEmailAsync(loginVM.EmailAddress);
    if(user != null)
    {
        var passwordCheck = await _userManager.CheckPasswordAsync(user, loginVM.Password);
        if (passwordCheck)
        {
            var result = await _signInManager.PasswordSignInAsync(user, loginVM.Password, false, false);
            if (result.Succeeded)
            {
              return RedirectToAction("Index", "Movies");
            }
        }
        TempData["Error"] = "Wrong credentials. Please, try again!";
        return View(loginVM);
    }

    TempData["Error"] = "Wrong credentials. Please, try again!";
    return View(loginVM);
}

can you help me by solution general working as session without using identity membership so i can use it on another login or another logic

 


Answers (2)