@@ -89,7 +89,8 @@ public SignInManager(UserManager<TUser> userManager,
89
89
/// <summary>
90
90
/// The <see cref="HttpContext"/> used.
91
91
/// </summary>
92
- public HttpContext Context {
92
+ public HttpContext Context
93
+ {
93
94
get
94
95
{
95
96
var context = _context ?? _contextAccessor ? . HttpContext ;
@@ -257,7 +258,7 @@ public virtual async Task<TUser> ValidateTwoFactorSecurityStampAsync(ClaimsPrinc
257
258
/// <param name="securityStamp">The expected security stamp value.</param>
258
259
/// <returns>True if the stamp matches the persisted value, otherwise it will return false.</returns>
259
260
public virtual async Task < bool > ValidateSecurityStampAsync ( TUser user , string securityStamp )
260
- => user != null && UserManager . SupportsUserSecurityStamp
261
+ => user != null && UserManager . SupportsUserSecurityStamp
261
262
&& securityStamp == await UserManager . GetSecurityStampAsync ( user ) ;
262
263
263
264
/// <summary>
@@ -279,7 +280,7 @@ public virtual async Task<SignInResult> PasswordSignInAsync(TUser user, string p
279
280
}
280
281
281
282
var attempt = await CheckPasswordSignInAsync ( user , password , lockoutOnFailure ) ;
282
- return attempt . Succeeded
283
+ return attempt . Succeeded
283
284
? await SignInOrTwoFactorAsync ( user , isPersistent )
284
285
: attempt ;
285
286
}
@@ -330,7 +331,13 @@ public virtual async Task<SignInResult> CheckPasswordSignInAsync(TUser user, str
330
331
331
332
if ( await UserManager . CheckPasswordAsync ( user , password ) )
332
333
{
333
- await ResetLockout ( user ) ;
334
+ var alwaysLockout = AppContext . TryGetSwitch ( "Microsoft.AspNetCore.Identity.CheckPasswordSignInAlwaysResetLockoutOnSuccess" , out var enabled ) && enabled ;
335
+ // Only reset the lockout when TFA is not enabled when not in quirks mode
336
+ if ( alwaysLockout || ! await IsTfaEnabled ( user ) )
337
+ {
338
+ await ResetLockout ( user ) ;
339
+ }
340
+
334
341
return SignInResult . Success ;
335
342
}
336
343
Logger . LogWarning ( 2 , "User {userId} failed to provide the correct password." , await UserManager . GetUserIdAsync ( user ) ) ;
@@ -534,7 +541,7 @@ public virtual async Task<TUser> GetTwoFactorAuthenticationUserAsync()
534
541
/// <param name="isPersistent">Flag indicating whether the sign-in cookie should persist after the browser is closed.</param>
535
542
/// <returns>The task object representing the asynchronous operation containing the <see name="SignInResult"/>
536
543
/// for the sign-in attempt.</returns>
537
- public virtual Task < SignInResult > ExternalLoginSignInAsync ( string loginProvider , string providerKey , bool isPersistent )
544
+ public virtual Task < SignInResult > ExternalLoginSignInAsync ( string loginProvider , string providerKey , bool isPersistent )
538
545
=> ExternalLoginSignInAsync ( loginProvider , providerKey , isPersistent , bypassTwoFactor : false ) ;
539
546
540
547
/// <summary>
@@ -645,7 +652,7 @@ public virtual async Task<IdentityResult> UpdateExternalAuthenticationTokensAsyn
645
652
646
653
return IdentityResult . Success ;
647
654
}
648
-
655
+
649
656
/// <summary>
650
657
/// Configures the redirect URL and user identifier for the specified external login <paramref name="provider"/>.
651
658
/// </summary>
@@ -708,7 +715,12 @@ private ClaimsIdentity CreateIdentity(TwoFactorAuthenticationInfo info)
708
715
}
709
716
return identity ;
710
717
}
711
-
718
+
719
+ private async Task < bool > IsTfaEnabled ( TUser user )
720
+ => UserManager . SupportsUserTwoFactor &&
721
+ await UserManager . GetTwoFactorEnabledAsync ( user ) &&
722
+ ( await UserManager . GetValidTwoFactorProvidersAsync ( user ) ) . Count > 0 ;
723
+
712
724
/// <summary>
713
725
/// Signs in the specified <paramref name="user"/> if <paramref name="bypassTwoFactor"/> is set to false.
714
726
/// Otherwise stores the <paramref name="user"/> for use after a two factor check.
@@ -720,10 +732,7 @@ private ClaimsIdentity CreateIdentity(TwoFactorAuthenticationInfo info)
720
732
/// <returns>Returns a <see cref="SignInResult"/></returns>
721
733
protected virtual async Task < SignInResult > SignInOrTwoFactorAsync ( TUser user , bool isPersistent , string loginProvider = null , bool bypassTwoFactor = false )
722
734
{
723
- if ( ! bypassTwoFactor &&
724
- UserManager . SupportsUserTwoFactor &&
725
- await UserManager . GetTwoFactorEnabledAsync ( user ) &&
726
- ( await UserManager . GetValidTwoFactorProvidersAsync ( user ) ) . Count > 0 )
735
+ if ( ! bypassTwoFactor && await IsTfaEnabled ( user ) )
727
736
{
728
737
if ( ! await IsTwoFactorClientRememberedAsync ( user ) )
729
738
{
0 commit comments