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)); }