23 lines
574 B
C#
23 lines
574 B
C#
using System.Security.Cryptography;
|
|
using System.Text;
|
|
|
|
namespace ASTRAIN.Api.Services;
|
|
|
|
public static class UserKeyGenerator
|
|
{
|
|
private const string Alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
|
|
|
public static string Generate(int length = 8)
|
|
{
|
|
var buffer = new byte[length];
|
|
RandomNumberGenerator.Fill(buffer);
|
|
var chars = new char[length];
|
|
for (var i = 0; i < length; i++)
|
|
{
|
|
chars[i] = Alphabet[buffer[i] % Alphabet.Length];
|
|
}
|
|
|
|
return new string(chars);
|
|
}
|
|
}
|