@@ -21,6 +21,7 @@ public class UserAuthenticationService : IUserAuthenticationService
21
21
private readonly int _delayTimeMultiplier = 400 ; //ms
22
22
private readonly int _maxInvalidLogins = 10 ;
23
23
private readonly int _maxInvalidLoginsBeforeDelay = 3 ;
24
+ private readonly int _timeoutDatabaseUpdate = 5 ; //s
24
25
25
26
/// <summary>
26
27
/// User Authentication Service
@@ -172,7 +173,7 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
172
173
throw new NullReferenceException ( nameof ( userEntity . PasswordHash ) ) ;
173
174
}
174
175
175
- using var cancellationTokenSource = new CancellationTokenSource ( TimeSpan . FromSeconds ( 5 ) ) ;
176
+ using var cancellationTokenSource = new CancellationTokenSource ( TimeSpan . FromSeconds ( this . _timeoutDatabaseUpdate ) ) ;
176
177
177
178
var passwordHash = PasswordHelper . HashPasword ( authenticationRequest . Password , userEntity . PasswordSalt ) ;
178
179
if ( userEntity . PasswordHash . SequenceEqual ( passwordHash ) )
@@ -197,7 +198,8 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
197
198
this . SetValidLogin ( authenticationRequest . IpAddress ) ;
198
199
this . SetValidLogin ( authenticationRequest . EmailAddress ) ;
199
200
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 => { } ) ; ;
201
203
202
204
return new AuthenticationResult
203
205
{
@@ -208,7 +210,8 @@ public async Task<AuthenticationResult> ValidateCredentialsAsync(
208
210
this . SetInvalidLogin ( authenticationRequest . IpAddress ) ;
209
211
this . SetInvalidLogin ( authenticationRequest . EmailAddress ) ;
210
212
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 => { } ) ; ;
212
215
213
216
return new AuthenticationResult
214
217
{
@@ -283,6 +286,10 @@ public async Task<ValidateTokenResult> ValidateTokenAsync(
283
286
if ( isTokenValid )
284
287
{
285
288
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 => { } ) ;
286
293
}
287
294
288
295
return new ValidateTokenResult
0 commit comments