From 2457fc2455f981adf05cc490c5d1dab5025000c6 Mon Sep 17 00:00:00 2001 From: RogueException Date: Thu, 21 Jan 2016 19:20:11 -0400 Subject: [PATCH] Fixed several issues with tokens cache --- src/Discord.Net/DiscordClient.cs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index dc0e4b807..97c36c173 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -226,25 +226,26 @@ namespace Discord byte[] cacheKey = null; //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); - oldToken = LoadToken(tokenPath, cacheKey); - ClientAPI.Token = oldToken; + if (token == null && password != null) + { + 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 response = await ClientAPI.Send(request).ConfigureAwait(false); token = response.Token; - if (Config.CacheToken && token != oldToken) + if (Config.CacheToken && token != oldToken && tokenPath != null) SaveToken(tokenPath, cacheKey, token); - ClientAPI.Token = token; //Cache other stuff