This repository has been archived on 2024-03-29. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Database.Account/Util/AccountTokenUtil.cs

38 lines
960 B
C#
Raw Permalink Normal View History

2024-01-27 13:06:07 +00:00
namespace FreeSR.Database.Account.Util
{
using FreeSR.Database.Account.Model;
public static class AccountTokenUtil
{
private const int AccountTokenLength = 128;
private const string TokenCharacters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
private static Random s_random;
static AccountTokenUtil()
{
s_random = new Random();
}
public static string Generate()
{
var token = "";
for (int i = 0; i < AccountTokenLength; i++)
{
token += TokenCharacters[s_random.Next(TokenCharacters.Length)];
}
return token;
}
public static bool Verify(AccountModel accountModel, string clientToken)
{
if (accountModel == null)
return false;
return string.Equals(accountModel.Token, clientToken);
}
}
}