Archived
1
0
Fork 0
forked from Moux23333/FreeSR
This repository has been archived on 2024-03-30. You can view files and clone it, but cannot push or open issues or pull requests.
FreeSR/FreeSR.Database.Account/Util/AccountTokenUtil.cs
2024-01-27 21:06:07 +08:00

37 lines
960 B
C#

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);
}
}
}