Esempio n. 1
0
        private void token_GotFocus(object sender, RoutedEventArgs e)
        {
            // Grab string stored in Windows Credential Manager
            string tokenfromCredManager = Helpers.GetTokenFromCredManager();

            // Check if user stored token in Windows credential Manager
            if (tokenfromCredManager == null)
            {
                foundCreds.Text = "You don't have a token saved in your Credential Manager";
                return;
            }

            // If decrypting dll exists then the user encrypted the token in Credential Manager
            if (!File.Exists(IniConfigInfo.configFilePath))
            {
                foundCreds.Text = "There is no config file that stores the decryption info";
                return;
            }

            // Check if the user created a decryption dll and stored / right info in config file
            if (File.Exists(IniConfigInfo.GetDllPath()))
            {
                tokenfromCredManager = Helpers.DecryptToken(tokenfromCredManager);
            }
            else
            {
                foundCreds.Text = "I can't find the decrypting method from your config file.";
                return;
            }

            if (tokenfromCredManager != null)
            {
                // Populate with decrypted token
                token.Password  = tokenfromCredManager;
                foundCreds.Text = "I found the token in your Credential Manager";
            }
            else
            {
                foundCreds.Text = "The config file is there but the info is wrong";
            }
        }
Esempio n. 2
0
        private void token_GotFocus(object sender, RoutedEventArgs e)
        {
            // Grab string stored in Windows Credential Manager
            string token = Helpers.GetTokenFromCredManager();

            // Try the config file
            if (File.Exists(IniConfigInfo.configFilePath))
            {
                // If it exists, get the token stored there
                string configToken = IniConfigInfo.GetToken();

                // If the token in config is different from the one in cred manager, user needs to resolve conflict
                if (token != null && token != configToken)
                {
                    foundCreds.Text = "There are two conflicting tokens in the config file and on Credential Manager. You may want to fix that first.";
                    return;
                }

                token = configToken;
            }

            // If it's still null after checking the config file
            if (token == null)
            {
                foundCreds.Text = "You don't have a token saved in your config file or Credential Manager.";
                return;
            }

            // Keep track if user has config file and/or decrypting dll
            bool configExists = File.Exists(IniConfigInfo.configFilePath);
            bool dllExists    = false;

            if (configExists)
            {
                dllExists = File.Exists(IniConfigInfo.GetDllPath());
            }

            // Check if the user created a decryption dll and stored / right info in config file
            if (configExists && dllExists)
            {
                token = Helpers.DecryptToken(token);
            }

            if (token != null)
            {
                // Populate with decrypted token
                this.token.Password = token;
                foundCreds.Text     = "I found the token in your config file or Credential Manager";

                if (!configExists)
                {
                    foundCreds.Text += ", but there was no config file containing decryption info. You'll be fine if you didn't encrypt the token.";
                }
                else if (!dllExists)
                {
                    foundCreds.Text += ", but there was no dll file containing decryption methods. You'll be fine if you didn't encrypt the token.";
                }
                // Add period to sentence if none of the conditions are satisfied
                else
                {
                    foundCreds.Text += ".";
                }
            }
            else
            {
                foundCreds.Text = "The config file is there but the info is wrong.";
            }
        }