dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.21k stars 9.95k forks source link

Avoid resetting AccessFailedCount by CheckPasswordSignIn in ASP.Net Identity #54733

Closed yasinadobe6 closed 5 months ago

yasinadobe6 commented 5 months ago

Is there an existing issue for this?

Describe the bug

Please Dont Say Its Not Possible...

If Cant-> Just Give Me New Strategy This Is My Program.cs :

//Options For Identity opt.Lockout.AllowedForNewUsers = true; //True Bcz I want Active For All Users opt.Lockout.DefaultLockoutTimeSpan = new TimeSpan(100, 1, 1, 1); //Its Like Ban For Ever opt.Lockout.MaxFailedAccessAttempts = 10; //Just Admin Can Increase This For Users

And This Is My Login Action For Authentication : Check Username -> _signInManager.UserManager.FindByNameAsync(model.Username); Check Password -> _signInManager.CheckPasswordSignInAsync(userId, Password, False) //False Because I dont Want Increse AccessFailedCount In DataBase For Wrong Password

Now Admin If Want Report a User(UserId) This Will Happen: _userManager.AccessFailedAsync(UserId); //Its Like Increase +1 AccessFailedCount In DataBase

Expected Behavior

So Now My expectation is that if the admin reports a user 10 times-> user Will Ban For Ever

But Problem Is This : if user login to my WebApi -> This Method _signInManager.CheckPasswordSignInAsync automatic Will Reset AccessFailedCount ...

How to Avoid resetting AccessFailedCount by This Method After one time Succeeded login user if we cant customize this... any suggestion?

Steps To Reproduce

No response

Exceptions (if any)

No response

.NET Version

8

Anything else?

ASP.NET Core Identity 8

mkArtakMSFT commented 5 months ago

Thanks for contacting us. You can override the ResetAccessFailedCount method in the UserStore if you provide your own implementation: https://learn.microsoft.com/dotnet/api/microsoft.aspnetcore.identity.usermanager-1.resetaccessfailedcountasync

While this may be a great idea, it is not aligned with our long-term vision to make it part of the framework. For many other ideas which don't belong to the framework we encourage the community to build and ship on their own, contributing to the expanding .NET Ecosystem.

You can learn more about our triage process and how we handle issues by reading our Triage Process writeup.