From 103a305c2550ffdc2d3a7efa5948ed55ecc8ffde Mon Sep 17 00:00:00 2001 From: Jonathan Date: Wed, 10 Jun 2020 12:12:09 +0200 Subject: [PATCH] Update TotpSecurityStampBasedTokenProvider.cs Add line breaks before return statement. Use string interpolation instead of string concatenation. Hyphenate the documentation. --- .../src/TotpSecurityStampBasedTokenProvider.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Identity/Extensions.Core/src/TotpSecurityStampBasedTokenProvider.cs b/src/Identity/Extensions.Core/src/TotpSecurityStampBasedTokenProvider.cs index 117fb0752f..987092e628 100644 --- a/src/Identity/Extensions.Core/src/TotpSecurityStampBasedTokenProvider.cs +++ b/src/Identity/Extensions.Core/src/TotpSecurityStampBasedTokenProvider.cs @@ -5,7 +5,7 @@ using System.Threading.Tasks; namespace Microsoft.AspNetCore.Identity { /// - /// Represents a token provider that generates time based codes using the user's security stamp. + /// Represents a token provider that generates time-based codes using the user's security stamp. /// /// The type encapsulating a user. public abstract class TotpSecurityStampBasedTokenProvider : IUserTwoFactorTokenProvider @@ -38,6 +38,7 @@ namespace Microsoft.AspNetCore.Identity } var token = await manager.CreateSecurityTokenAsync(user); var modifier = await GetUserModifierAsync(purpose, manager, user); + return Rfc6238AuthenticationService.GenerateCode(token, modifier).ToString("D6", CultureInfo.InvariantCulture); } @@ -67,6 +68,7 @@ namespace Microsoft.AspNetCore.Identity } var securityToken = await manager.CreateSecurityTokenAsync(user); var modifier = await GetUserModifierAsync(purpose, manager, user); + return securityToken != null && Rfc6238AuthenticationService.ValidateCode(securityToken, code, modifier); } @@ -87,11 +89,12 @@ namespace Microsoft.AspNetCore.Identity throw new ArgumentNullException(nameof(manager)); } var userId = await manager.GetUserIdAsync(user); - return "Totp:" + purpose + ":" + userId; + + return $"{Totp}:{purpose}:{userId}"; } /// - /// Returns a flag indicating whether the token provider can generate a token suitable for two factor authentication token for + /// Returns a flag indicating whether the token provider can generate a token suitable for two-factor authentication token for /// the specified . /// /// The that can be used to retrieve user properties. @@ -99,8 +102,8 @@ namespace Microsoft.AspNetCore.Identity /// /// The that represents the asynchronous operation, containing the a flag indicating if a two /// factor token could be generated by this provider for the specified . - /// The task will return true if a two factor authentication token could be generated, otherwise false. + /// The task will return true if a two-factor authentication token could be generated, otherwise false. /// public abstract Task CanGenerateTwoFactorTokenAsync(UserManager manager, TUser user); } -} \ No newline at end of file +}