mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-01 18:57:24 +00:00
Capitalizes the first word and adds the terminal period across the domain, application, data access, infrastructure, API and web layers and the plugins. No comment is reworded. The change also normalizes the TODO bodies to lowercase, leaves commented-out code untouched, corrects the Threat/Treat typo and the dangling hyphen in the exception middleware, and collapses two accidental repeated terminal periods.
35 lines
1.3 KiB
C#
35 lines
1.3 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
using OtpNet;
|
|
#endregion
|
|
|
|
namespace Lumina.Infrastructure.Core.Authentication;
|
|
|
|
/// <summary>
|
|
/// Service for generating and validating TOTP tokens.
|
|
/// </summary>
|
|
public class TotpTokenGenerator : ITotpTokenGenerator
|
|
{
|
|
/// <summary>
|
|
/// Generates a new TOTP secret for a user.
|
|
/// </summary>
|
|
/// <returns>The generated TOTP secret.</returns>
|
|
public byte[] GenerateSecret()
|
|
{
|
|
return KeyGeneration.GenerateRandomKey(); // Generate a random key for TOTP.
|
|
}
|
|
|
|
/// <summary>
|
|
/// Validates a TOTP token against the stored secret.
|
|
/// </summary>
|
|
/// <param name="secret">The user's TOTP secret.</param>
|
|
/// <param name="token">The token to validate.</param>
|
|
/// <returns><see langword="true"/> if valid, <see langword="false"/> otherwise.</returns>
|
|
public bool ValidateToken(byte[] secret, string token)
|
|
{
|
|
Totp totp = new(secret);
|
|
// Verify the TOTP token, allowing for slight time drifts between server and client.
|
|
return totp.VerifyTotp(token, out _, VerificationWindow.RfcSpecifiedNetworkDelay);
|
|
}
|
|
}
|