Click here to Skip to main content
15,794,275 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I work on web application mvc core .net 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 .

so how to using session to allow user enter three time password wrong

after three time account will blocked

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

What I have tried:

   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);
Updated 2-Dec-22 0:03am

1 solution

Configure ASP.NET Core Identity | Microsoft Learn[^]

The documentation clearly describes how to enable, configure, and use the lockout feature.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900