The AccessFailedAsync method is used to increment the failed access count and lockout the user if the maximum attempts exceed. This method is generally used in the context of identity management and security to protect against brute-force attacks.
Code Examples:
Example 1:
//Increment failed access count and store it in user object var accessCount = await userManager.AccessFailedAsync(user);
//Logic to lockout user after maximum attempts if (accessCount >= userManager.MaxFailedAccessAttemptsBeforeLockout) { await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow.AddMinutes(userManager.DefaultAccountLockoutTimeSpan.TotalMinutes)); }
Example 2:
//Custom logic to lockout user after maximum attempts var accessCount = await userManager.AccessFailedAsync(user);
if (accessCount >= 5) //Change the maximum attempts as per requirement { await userManager.SetLockoutEndDateAsync(user, DateTimeOffset.UtcNow.AddDays(1)); //Lockout user for 24 hours }
Package Library:
The AccessFailedAsync method is part of the ApplicationUserManager class in the Microsoft.AspNet.Identity.Core package. This package provides core functionality for identity management in ASP.NET applications.
C# (CSharp) ApplicationUserManager.AccessFailedAsync - 18 examples found. These are the top rated real world C# (CSharp) examples of ApplicationUserManager.AccessFailedAsync from package code extracted from open source projects. You can rate examples to help us improve the quality of examples.