feat: scaffold backend and shared library
This commit is contained in:
22
src/ASTRAIN.Api/Services/UserKeyGenerator.cs
Normal file
22
src/ASTRAIN.Api/Services/UserKeyGenerator.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user