Fixed several issues with tokens cache

This commit is contained in:
RogueException
2016-01-21 19:20:11 -04:00
parent 9f66857efa
commit 2457fc2455

View File

@@ -226,25 +226,26 @@ namespace Discord
byte[] cacheKey = null; byte[] cacheKey = null;
//Get Token //Get Token
if (token == null && Config.CacheToken) if (email != null && Config.CacheToken)
{ {
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password,
new byte[] { 0x5A, 0x2A, 0xF8, 0xCF, 0x78, 0xD3, 0x7D, 0x0D });
cacheKey = deriveBytes.GetBytes(16);
tokenPath = GetTokenCachePath(email); tokenPath = GetTokenCachePath(email);
oldToken = LoadToken(tokenPath, cacheKey); if (token == null && password != null)
ClientAPI.Token = oldToken; {
Rfc2898DeriveBytes deriveBytes = new Rfc2898DeriveBytes(password,
new byte[] { 0x5A, 0x2A, 0xF8, 0xCF, 0x78, 0xD3, 0x7D, 0x0D });
cacheKey = deriveBytes.GetBytes(16);
oldToken = LoadToken(tokenPath, cacheKey);
token = oldToken;
}
} }
else
ClientAPI.Token = token; ClientAPI.Token = token;
var request = new LoginRequest() { Email = email, Password = password }; var request = new LoginRequest() { Email = email, Password = password };
var response = await ClientAPI.Send(request).ConfigureAwait(false); var response = await ClientAPI.Send(request).ConfigureAwait(false);
token = response.Token; token = response.Token;
if (Config.CacheToken && token != oldToken) if (Config.CacheToken && token != oldToken && tokenPath != null)
SaveToken(tokenPath, cacheKey, token); SaveToken(tokenPath, cacheKey, token);
ClientAPI.Token = token; ClientAPI.Token = token;
//Cache other stuff //Cache other stuff