How to enable AccessFailedCount and lock features in ASP.net Identity 2.0?

I am trying to increase AccessFailedCount with this code, but it does not work (in the AspNetUsers table the number of AccessFailed does not increase). => In this code, My first reaction was that when the user was unable to log in to increase the AccessFailed account, but did not work with this code. Please give me a suggestion for the upgrade code and any things.

                var manager = Context.GetOwinContext().GetUserManager<ApplicationUserManager>();

                // find user by username first
                var user = manager.FindByName(txtUserName.Text);

                if (user != null)
                {
                        var validCredentials = manager.Find(txtUserName.Text, txtPassword.Text);

                        // When a user is lockedout, this check is done to ensure that even if the credentials are valid
                        // the user can not login until the lockout duration has passed
                        if (manager.IsLockedOut(user.Id))
                        {
                         error message;
                        }

                        // if user is subject to lockouts and the credentials are invalid
                        // record the failure and check if user is lockedout and display message, otherwise,
                        // display the number of attempts remaining before lockout
                        else if (manager.GetLockoutEnabled(user.Id) && validCredentials == null && manager.SupportsUserLockout)
                        {
                            // Record the failure which also may cause the user to be locked out
                            manager.AccessFailed(user.Id);

                            if (manager.IsLockedOut(user.Id))
                            {
                                error message;
                            }
                            else
                            {
                                int accessFailedCount = manager.GetAccessFailedCount(user.Id);

                            }

                        }
                        else
                        {

                                    IdentityHelper.SignIn(manager, user, RememberMe.Checked);

                                    // When token is verified correctly, clear the access failed count used for lockout
                                    manager.ResetAccessFailedCount(user.Id);
                                    Response.Redirect("/Home.aspx", false);

                        }

                  }
+4
source share
1 answer

You probably want to learn the SignInManager class in ASP.NET Identity 2.1. See this blog post for more information on ASP.NET Identity 2.1.0-alpha1

SignInManager , .

SignInStatus result = await _signInManager.PasswordSignInAsync(model.Username, model.Password, model.RememberMe, true);

.

switch (result)
{
    case SignInStatus.Success:
        // Login success
    case SignInStatus.LockedOut:
        // Account locked out
    case SignInStatus.RequiresVerification:
        // Do two factor verification
    case SignInStatus.Failure:
    default:
        // Login failure
}
+1

All Articles