コード例 #1
0
        public static string HandleTokenDecrypt()
        {
            if (BotToken.UsingPassword())
            {
                bool retry = true;
                while (retry)
                {
                    Console.Write("Enter your password: "******"Checksum mismatch. (New bot version or corrupted file)");
                        return(PromptAndStoreToken());
                    }
                    else if (!verified)
                    {
                        Console.Write("Could not decrypt token with that password. Try again? (y/n) ");
                        string yesno = Console.ReadLine();
                        retry = (yesno.Length > 0 && yesno.Substring(0, 1).ToLower() == "y");
                    }
                    else
                    {
                        Console.WriteLine("Token decrypted.");
                        return(BotToken.GetTokenString());
                    }
                }
                // User decided to stop retrying
                string pathToTokenFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "token").ToString();
                Console.WriteLine($"Store a new token by deleting the token file at {pathToTokenFile}");
            }
            else
            {
                bool verified = BotToken.DecryptAndVerify();
                if (!verified)
                {
                    Console.WriteLine("Checksum mismatch. (New bot version or corrupted file)");
                    return(PromptAndStoreToken());
                }
                else
                {
                    Console.WriteLine("Token decrypted.");
                    return(BotToken.GetTokenString());
                }
            }

            // Couldn't get a token
            return("");
        }
コード例 #2
0
        private static string PromptAndStoreToken()
        {
            Console.Write("The Discord bot token needs to be stored. Enter the token: ");
            string token = Console.ReadLine();

            Console.WriteLine(
                Environment.NewLine +
                "The token will be stored encrypted. You may choose to a use a password to encrypt it. " +
                "If you don't use a password, a default encryption scheme will be used (this is less secure). " +
                Environment.NewLine
                );

            Console.Write("Use a password? (y/n) ");
            string yesno = Console.ReadLine();

            bool usePassword = (yesno.Length > 0 && yesno.Substring(0, 1).ToLower() == "y");

            string password = String.Empty;

            if (usePassword)
            {
                do
                {
                    Console.Write("Enter your password: "******"WARNING: If you forget your password you will have to delete the token file and re-encrypt the token.");
            }
            else
            {
                Console.WriteLine("Using default encryption.");
            }

            BotToken.WriteToken(token, password);
            return(BotToken.GetTokenString());
        }
コード例 #3
0
 private static string StoreToken(string token, string password)
 {
     BotToken.WriteToken(token, password);
     return(BotToken.GetTokenString());
 }