3

I'm using asp.net Identity and I have added an "Active" property to my ApplicationUser.

If I set the Active property to false, the user should not be able to sign in even if the username and passwordis correct.

Ho to achieve this? Can anyone point me in the right direction?

Rajesh Shetty
  • 86
  • 1
  • 8

1 Answers1

4

In AccountController.cs update Login Method in case of success for result try this

 var user = db.AspNetUsers.FirstOrDefault(s => s.Email == model.Email);
 if(user.Active == false)
 {
 AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
    ModelState.AddModelError("", "Invalid login attempt.");
    return View(model);
 }
 else 
 {
    return RedirectToLocal(returnUrl);
 }
Saqib A. Azhar
  • 994
  • 1
  • 15
  • 27