Implements authentication system

This commit is contained in:
BinaryAlley committed 2024-11-11 22:57:33 +02:00
1 parent 38829d64ff
commit a6dcf65d1c
103 files changed
+2983 -454

No files matched your search

@@ -0,0 +1,27 @@
#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('=');
}
}