1
0
mirror of https://github.com/bitwarden/server synced 2025-12-15 15:53:59 +00:00

feat(otp): [PM-18612] Consolidate all email OTP to use 6 digits

* Change email OTP to 6 digits

* Added comment on base class
This commit is contained in:
Todd Martin
2025-07-07 15:52:30 -04:00
committed by GitHub
parent 79ad1dbda0
commit 737f549f82
2 changed files with 10 additions and 6 deletions

View File

@@ -7,6 +7,9 @@ using Microsoft.Extensions.DependencyInjection;
namespace Bit.Core.Auth.Identity.TokenProviders;
/// <summary>
/// Generates and validates tokens for email OTPs.
/// </summary>
public class EmailTokenProvider : IUserTwoFactorTokenProvider<User>
{
private const string CacheKeyFormat = "EmailToken_{0}_{1}_{2}";
@@ -25,7 +28,7 @@ public class EmailTokenProvider : IUserTwoFactorTokenProvider<User>
};
}
public int TokenLength { get; protected set; } = 8;
public int TokenLength { get; protected set; } = 6;
public bool TokenAlpha { get; protected set; } = false;
public bool TokenNumeric { get; protected set; } = true;

View File

@@ -7,17 +7,18 @@ using Microsoft.Extensions.DependencyInjection;
namespace Bit.Core.Auth.Identity.TokenProviders;
/// <summary>
/// Generates tokens for email two-factor authentication.
/// It inherits from the EmailTokenProvider class, which manages the persistence and validation of tokens,
/// and adds additional validation to ensure that 2FA is enabled for the user.
/// </summary>
public class EmailTwoFactorTokenProvider : EmailTokenProvider
{
public EmailTwoFactorTokenProvider(
[FromKeyedServices("persistent")]
IDistributedCache distributedCache) :
base(distributedCache)
{
TokenAlpha = false;
TokenNumeric = true;
TokenLength = 6;
}
{ }
public override Task<bool> CanGenerateTwoFactorTokenAsync(UserManager<User> manager, User user)
{