fork from 1.3
This commit is contained in:
37
FreeSR.Database.Account/Util/AccountTokenUtil.cs
Normal file
37
FreeSR.Database.Account/Util/AccountTokenUtil.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user