mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 00:11:10 +00:00
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
#region ========================================================================= USING =====================================================================================
|
|
using Lumina.Application.Common.Infrastructure.Authentication;
|
|
using System;
|
|
using System.Security.Cryptography;
|
|
#endregion
|
|
|
|
namespace Lumina.Infrastructure.Core.Authentication;
|
|
|
|
/// <summary>
|
|
/// Service for the service for generating secure tokens for accounts confirmation or recovery.
|
|
/// </summary>
|
|
public class TokenGenerator : ITokenGenerator
|
|
{
|
|
/// <summary>
|
|
/// Generates a secure token.
|
|
/// </summary>
|
|
/// <returns>A secure token.</returns>
|
|
public string GenerateToken()
|
|
{
|
|
// allocate an array for the token data
|
|
byte[] tokenData = new byte[32];
|
|
// fill the array with a cryptographically strong sequence of random values
|
|
RandomNumberGenerator.Fill(tokenData);
|
|
// convert to a Base64 string, but replace URL-unsafe characters '+' and '/' with '-' and '_', and remove padding characters ('=')
|
|
return Convert.ToBase64String(tokenData).Replace('+', '-').Replace('/', '_').TrimEnd('=');
|
|
}
|
|
}
|