Skip to content

Commit 2ce63e5

Browse files
committed
fixes
1 parent 0c41047 commit 2ce63e5

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/Backend/Nager.AuthenticationService.WebApi/Services/UserAuthenticationService.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public class UserAuthenticationService : IUserAuthenticationService
2121
private readonly int _delayTimeMultiplier = 400; //ms
2222
private readonly int _maxInvalidLogins = 10;
2323
private readonly int _maxInvalidLoginsBeforeDelay = 3;
24+
private readonly int _timeoutDatabaseUpdate = 5; //s
2425

2526
/// <summary>
2627
/// User Authentication Service
@@ -172,7 +173,7 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
172173
throw new NullReferenceException(nameof(userEntity.PasswordHash));
173174
}
174175

175-
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
176+
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(this._timeoutDatabaseUpdate));
176177

177178
var passwordHash = PasswordHelper.HashPasword(authenticationRequest.Password, userEntity.PasswordSalt);
178179
if (userEntity.PasswordHash.SequenceEqual(passwordHash))
@@ -197,7 +198,8 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
197198
this.SetValidLogin(authenticationRequest.IpAddress);
198199
this.SetValidLogin(authenticationRequest.EmailAddress);
199200

200-
await this._userRepository.SetLastSuccessfulValidationTimestampAsync(o => o.Id == userEntity.Id, cancellationTokenSource.Token);
201+
await this._userRepository.SetLastSuccessfulValidationTimestampAsync(o => o.Id == userEntity.Id, cancellationTokenSource.Token)
202+
.ContinueWith(task => { }); ;
201203

202204
return new AuthenticationResult
203205
{
@@ -208,7 +210,8 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
208210
this.SetInvalidLogin(authenticationRequest.IpAddress);
209211
this.SetInvalidLogin(authenticationRequest.EmailAddress);
210212

211-
await this._userRepository.SetLastValidationTimestampAsync(o => o.Id == userEntity.Id, cancellationTokenSource.Token);
213+
await this._userRepository.SetLastValidationTimestampAsync(o => o.Id == userEntity.Id, cancellationTokenSource.Token)
214+
.ContinueWith(task => { }); ;
212215

213216
return new AuthenticationResult
214217
{
@@ -283,6 +286,10 @@ public async Task<ValidateTokenResult> ValidateTokenAsync(
283286
if (isTokenValid)
284287
{
285288
this._memoryCache.Remove(cacheKey);
289+
290+
using var cancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(this._timeoutDatabaseUpdate));
291+
await this._userRepository.SetLastSuccessfulValidationTimestampAsync(o => o.Id == userEntity.Id, cancellationTokenSource.Token)
292+
.ContinueWith(task => { });
286293
}
287294

288295
return new ValidateTokenResult

0 commit comments

Comments
 (0)