Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit aee2400

Browse files
user lockout in asp.net core
1 parent 4c6783c commit aee2400

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

‎Webgentle.BookStore/Webgentle.BookStore/Controllers/AccountController.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public async Task<IActionResult> Login(SignInModel signInModel, string returnUrl
7575
{
7676
ModelState.AddModelError("", "Not allowed to login");
7777
}
78+
else if (result.IsLockedOut)
79+
{
80+
ModelState.AddModelError("", "Account blocked. Try after some time.");
81+
}
7882
else
7983
{
8084
ModelState.AddModelError("", "Invalid credentials");

‎Webgentle.BookStore/Webgentle.BookStore/Repository/AccountRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public async Task GenerateForgotPasswordTokenAsync(ApplicationUser user)
7676

7777
public async Task<SignInResult> PasswordSignInAsync(SignInModel signInModel)
7878
{
79-
return await _signInManager.PasswordSignInAsync(signInModel.Email, signInModel.Password, signInModel.RememberMe, false);
79+
return await _signInManager.PasswordSignInAsync(signInModel.Email, signInModel.Password, signInModel.RememberMe, true);
8080
}
8181

8282
public async Task SignOutAsync()

‎Webgentle.BookStore/Webgentle.BookStore/Startup.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ public void ConfigureServices(IServiceCollection services)
4949
options.Password.RequireUppercase = false;
5050

5151
options.SignIn.RequireConfirmedEmail = true;
52+
53+
options.Lockout.DefaultLockoutTimeSpan = TimeSpan.FromMinutes(20);
54+
options.Lockout.MaxFailedAccessAttempts = 3;
55+
});
56+
57+
services.Configure<DataProtectionTokenProviderOptions>(options =>
58+
{
59+
options.TokenLifespan = TimeSpan.FromMinutes(5);
5260
});
5361

5462
services.ConfigureApplicationCookie(config =>

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /