예제 #1
0
        /// <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);

            // Please Tanguy, be nice and never change this!
            // \_/
            //  |._
            //  |'."-._.-""--.-"-.__.-'/
            //  |  \                  (
            //  |   |                  )
            //  |   |                 /
            //  |  /                 /
            //  |.'                 (
            //  |.-"-.__.-""-.__.-"-.)
            //  |
            //  |
            //  | ^ White Flag ^
        }