From fee305d154685731b1bd2783e0fabb78ee4b01ae Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Thu, 29 Nov 2018 22:06:48 -0800 Subject: [PATCH] Update the minimum bot token length to 58 char - Updates the minimum length of a bot token to be 58 characters. An older 58 char bot token was found by Moiph - Makes this value an internal const instead of a magic number --- src/Discord.Net.Core/Utils/TokenUtils.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.Core/Utils/TokenUtils.cs b/src/Discord.Net.Core/Utils/TokenUtils.cs index bfc915252..8fa846267 100644 --- a/src/Discord.Net.Core/Utils/TokenUtils.cs +++ b/src/Discord.Net.Core/Utils/TokenUtils.cs @@ -7,6 +7,15 @@ namespace Discord /// public static class TokenUtils { + /// + /// The minimum length of a Bot token. + /// + /// + /// This value was determined by comparing against the examples in the Discord + /// documentation, and pre-existing tokens. + /// + internal const int MinBotTokenLength = 58; + /// /// Checks the validity of the supplied token of a specific type. /// @@ -29,11 +38,11 @@ namespace Discord // no validation is performed on Bearer tokens break; case TokenType.Bot: - // bot tokens are assumed to be at least 59 characters in length + // bot tokens are assumed to be at least 58 characters in length // this value was determined by referencing examples in the discord documentation, and by comparing with // pre-existing tokens - if (token.Length < 59) - throw new ArgumentException(message: "A Bot token must be at least 59 characters in length.", paramName: nameof(token)); + if (token.Length < MinBotTokenLength) + throw new ArgumentException(message: $"A Bot token must be at least {MinBotTokenLength} characters in length.", paramName: nameof(token)); break; default: // All unrecognized TokenTypes (including User tokens) are considered to be invalid.