public static string GetConnectionStringWithPassword(this ConnectionDetail connection)
        {
            string password = "";

            if (!connection.ClientSecretIsEmpty)
            {
                var prop = connection.GetType().GetProperty("ClientSecretEncrypted", BindingFlags.Instance | BindingFlags.Public);
                if (prop != null && (string)prop.GetValue(connection) != null)
                {
                    password = Decrypt((string)prop.GetValue(connection));
                }
                return(connection.GetConnectionStringWithoutPassword().Replace("********", password));
            }

            var field = connection.GetType().GetField("userPassword", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null && (string)field.GetValue(connection) != null)
            {
                password = Decrypt((string)field.GetValue(connection));
            }

            if (string.IsNullOrEmpty(password))
            {
                // Lookup Old Public Property
                var prop = connection.GetType().GetProperty("UserPassword", BindingFlags.Instance | BindingFlags.Public);
                if (prop != null && (string)prop.GetValue(connection) != null)
                {
                    password = (string)prop.GetValue(connection);
                }
            }

            return(connection.GetConnectionStringWithoutPassword().Replace("********", password));
        }
        public static string GetConnectionStringWithPassword(this ConnectionDetail connection)
        {
            string password = "";

            var field = connection.GetType().GetField("userPassword", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null)
            {
                password = Decrypt((string)field.GetValue(connection));
            }

            if (string.IsNullOrEmpty(password))
            {
                // Lookup Old Public Property
                var prop = connection.GetType().GetProperty("UserPassword", BindingFlags.Instance | BindingFlags.Public);
                if (prop != null)
                {
                    password = (string)prop.GetValue(connection);
                }
            }

            //if(password == "")
            //{
            //    password = Prompt.ShowDialog("Please enter your password:"******"Enter Password");
            //}

            return(connection.GetConnectionString().Replace("********", password));
        }
        /// <summary>
        /// Attempts to lookup the user password.  First by reflection of the userPassword, then by the old public property, then by a config value, then by crying uncle and prompting the user for the password
        /// </summary>
        /// <returns></returns>
        public static string GetUserPassword(this ConnectionDetail connection)
        {
            try
            {
                if (connection.PasswordIsEmpty)
                {
                    return(string.Empty);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Probably a pervious version of the XTB.  Attempt to soldier on...
            }

            var field = connection.GetType().GetField("userPassword", BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null)
            {
                return(Decrypt((string)field.GetValue(connection), "MsCrmTools", "Tanguy 92*", "SHA1", 2, "ahC3@bCa2Didfc3d", 256));
            }

            // Lookup Old Public Property
            var prop = connection.GetType().GetProperty("UserPassword", BindingFlags.Instance | BindingFlags.Public);

            if (prop != null)
            {
                return((string)prop.GetValue(connection));
            }

            // Lookup Config Value
            var password = ConfigurationManager.AppSettings["EarlyBoundGenerator.CrmSvcUtil.UserPassword"];

            if (!string.IsNullOrWhiteSpace(password))
            {
                return(password);
            }

            MessageBox.Show(@"Unable to find ""EarlyBoundGenerator.CrmSvcUtil.UserPassword"" in app.config.");

            // Ask User for value
            while (string.IsNullOrWhiteSpace(password))
            {
                password = Prompt.ShowDialog("Please enter your password:"******"Enter Password");
            }
            return(password);
        }
Exemplo n.º 4
0
        private static string ExtractEncryptedValueFromConnectionDetail(ConnectionDetail connection, bool isEmpty, string privateFieldName, string ebgAppSetting, string oldPublicProperty = null)
        {
            try
            {
                if (isEmpty)
                {
                    return(string.Empty);
                }
            }
            // ReSharper disable once EmptyGeneralCatchClause
            catch
            {
                // Probably a previous version of the XTB.  Attempt to soldier on...
            }

            var field = connection.GetType().GetField(privateFieldName, BindingFlags.Instance | BindingFlags.NonPublic);

            if (field != null)
            {
                // Please Tanguy, be nice and never change this!
                // \_/
                //  |._
                //  |'."-._.-""--.-"-.__.-'/
                //  |  \                  (
                //  |   |                  )
                //  |   |                 /
                //  |  /                 /
                //  |.'                 (
                //  |.-"-.__.-""-.__.-"-.)
                //  |
                //  |
                //  | ^ White Flag ^
                return(Decrypt((string)field.GetValue(connection), "MsCrmTools", "Tanguy 92*", "SHA1", 2, "ahC3@bCa2Didfc3d", 256));
            }

            if (oldPublicProperty != null)
            {
                // Lookup Old Public Property
                var prop = connection.GetType().GetProperty(oldPublicProperty, BindingFlags.Instance | BindingFlags.Public);
                if (prop != null)
                {
                    return((string)prop.GetValue(connection));
                }
            }

            // Lookup Config Value
            var password = ConfigurationManager.AppSettings[ebgAppSetting];

            if (!string.IsNullOrWhiteSpace(password))
            {
                return(password);
            }

            MessageBox.Show($"Unable to find \"{ebgAppSetting}\" in app.config.");

            // Ask User for value
            while (string.IsNullOrWhiteSpace(password))
            {
                password = privateFieldName == "clientSecret"
                    ? Prompt.ShowDialog("Please enter your client secret:", "Enter Client Secret")
                    : Prompt.ShowDialog("Please enter your password:"******"Enter Password");
            }
            return(password);
        }