예제 #1
0
파일: Utils.cs 프로젝트: pointydev/SAM
        public static List <Account> PasswordDeserialize(string file, string password)
        {
            object obj = null;

            try
            {
                string contents = File.ReadAllText(file);
                contents = StringCipher.Decrypt(contents, password);

                var stream = new MemoryStream(Encoding.UTF8.GetBytes(contents));

                var ser = new XmlSerializer(typeof(List <Account>));
                obj = ser.Deserialize(stream);

                stream.Close();
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }

            return((List <Account>)obj);
        }
예제 #2
0
        private void editEntry(object butt)
        {
            Button button = butt as Button;
            int    index  = Int32.Parse(button.Tag.ToString());

            var dialog = new TextDialog();

            dialog.AccountText     = decryptedAccounts[index].Name;
            dialog.PasswordText    = decryptedAccounts[index].Password;
            dialog.UrlText         = decryptedAccounts[index].ProfUrl;
            dialog.DescriptionText = decryptedAccounts[index].Description;

            // Reload slected boolean
            if (settingsFile.Read("Selected", "AutoLog") == "True")
            {
                selected = true;
            }
            else
            {
                selected = false;
            }

            if (selected == true && selectedAcc == index)
            {
                dialog.autoLogCheckBox.IsChecked = true;
            }

            if (dialog.ShowDialog() == true)
            {
                string aviUrl = htmlAviScrape(dialog.UrlText);

                // If the auto login checkbox was checked, update settings file and global variables.
                if (dialog.AutoLogAccountIndex == true)
                {
                    settingsFile.Write("SelectedAcc", button.Tag.ToString(), "AutoLog");
                    settingsFile.Write("Selected", "True", "AutoLog");
                    settingsFile.Write("Recent", "False", "AutoLog");
                    selected    = true;
                    recent      = false;
                    selectedAcc = index;
                }
                else
                {
                    settingsFile.Write("SelectedAcc", "-1", "AutoLog");
                    settingsFile.Write("Selected", "False", "AutoLog");
                    selected    = false;
                    selectedAcc = -1;
                }

                try
                {
                    // Encrypt info before saving to file
                    ePassword = StringCipher.Encrypt(dialog.PasswordText, eKey);

                    encryptedAccounts[index].Name        = dialog.AccountText;
                    encryptedAccounts[index].Password    = ePassword;
                    encryptedAccounts[index].ProfUrl     = dialog.UrlText;
                    encryptedAccounts[index].AviUrl      = aviUrl;
                    encryptedAccounts[index].Description = dialog.DescriptionText;

                    Utils.Serialize(encryptedAccounts);
                    RefreshWindow();
                }
                catch (Exception m)
                {
                    MessageBox.Show(m.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                    editEntry(butt);
                }
            }
        }
예제 #3
0
        private void postDeserializedRefresh(bool seedAcc)
        {
            if (encryptedAccounts != null)
            {
                int bCounter = 0;
                int xcounter = 0;
                int ycounter = 0;

                // Create new button and textblock for each account
                foreach (var account in encryptedAccounts)
                {
                    string temppass = StringCipher.Decrypt(account.Password, eKey);

                    if (seedAcc)
                    {
                        decryptedAccounts.Add(new Account()
                        {
                            Name = account.Name, Password = temppass, ProfUrl = account.ProfUrl, AviUrl = account.AviUrl, Description = account.Description
                        });
                    }

                    //Console.WriteLine("Name = {0}, Pass = {1}, Url = {2}", account.Name, account.Password, account.Url);
                    //Console.WriteLine("Name = {0}, Pass = {1}, Url = {2}", account.Name, temppass, account.Url);

                    Button    accountButton = new Button();
                    TextBlock accountText   = new TextBlock();

                    accountButton.Style = (Style)Resources["MyButtonStyle"];

                    accountButton.Tag = bCounter.ToString();

                    //accountButton.Name = account.Name;
                    //accountText.Name = account.Name + "Label";
                    accountText.Text = account.Name;

                    // If there is a description, set up tooltip.
                    if (account.Description != null && account.Description.Length > 0)
                    {
                        accountButton.ToolTip = account.Description;
                    }

                    accountButton.Height = 100;
                    accountButton.Width  = 100;
                    accountText.Height   = 30;
                    accountText.Width    = 100;

                    accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                    accountButton.VerticalAlignment   = VerticalAlignment.Top;
                    accountText.HorizontalAlignment   = HorizontalAlignment.Left;
                    accountText.VerticalAlignment     = VerticalAlignment.Top;

                    accountButton.Margin = new Thickness(15 + (xcounter * 120), (ycounter * 120) + 14, 0, 0);
                    accountText.Margin   = new Thickness(15 + (xcounter * 120), (ycounter * 120) + 113, 0, 0);

                    accountButton.BorderBrush = null;
                    accountText.Foreground    = new SolidColorBrush(Colors.White);

                    if (account.ProfUrl == "" || account.AviUrl == null || account.AviUrl == "" || account.AviUrl == " ")
                    {
                        accountButton.Content    = account.Name;
                        accountButton.Background = System.Windows.Media.Brushes.LightGray;
                    }
                    else
                    {
                        try
                        {
                            ImageBrush  brush1 = new ImageBrush();
                            BitmapImage image1 = new BitmapImage(new Uri(account.AviUrl));
                            brush1.ImageSource       = image1;
                            accountButton.Background = brush1;
                            buttonGrid.Children.Add(accountText);
                        }
                        catch (Exception m)
                        {
                            // Probably no internet connection or avatar url is bad
                            Console.WriteLine("Error: " + m.Message);

                            accountButton.Content = account.Name;
                        }
                    }

                    buttonGrid.Children.Add(accountButton);

                    accountButton.Click += new RoutedEventHandler(AccountButton_Click);
                    ContextMenu accountContext = new ContextMenu();
                    MenuItem    deleteItem     = new MenuItem();
                    MenuItem    editItem       = new MenuItem();
                    deleteItem.Header = "Delete";
                    editItem.Header   = "Edit";
                    accountContext.Items.Add(editItem);
                    accountContext.Items.Add(deleteItem);
                    accountButton.ContextMenu = accountContext;
                    deleteItem.Click         += delegate { deleteEntry(accountButton); };
                    editItem.Click           += delegate { editEntry(accountButton); };

                    bCounter++;
                    xcounter++;

                    if ((xcounter % Int32.Parse(accPerRow) == 0) && xcounter != 0)
                    {
                        ycounter++;
                        xcounter = 0;
                    }
                }

                int xval = 0;
                int newHeight;

                // Adjust window size and info positions
                if (ycounter == 0)
                {
                    xval              = xcounter + 1;
                    newHeight         = 190;
                    buttonGrid.Height = 141;
                }
                else
                {
                    xval              = Int32.Parse(accPerRow);
                    newHeight         = 185 + (125 * ycounter);
                    buttonGrid.Height = 141 * (125 + ycounter);
                }

                int newWidth = (xval * 120) + 25;

                resize(newHeight, newWidth);
                buttonGrid.Width = newWidth;

                // Adjust new account button
                NewButton.Margin = new Thickness(33 + (xcounter * 120), (ycounter * 120) + 52, 0, 0);
            }
        }
예제 #4
0
        private void NewAccount()
        {
            // User entered info
            var dialog = new TextDialog();

            if (dialog.ShowDialog() == true && dialog.AccountText != "" && dialog.PasswordText != "")
            {
                account = dialog.AccountText;
                string password     = dialog.PasswordText;
                string sharedSecret = dialog.SharedSecretText;

                string aviUrl;
                if (dialog.AviText != null && dialog.AviText.Length > 1)
                {
                    aviUrl = dialog.AviText;
                }
                else
                {
                    aviUrl = Utils.HtmlAviScrape(dialog.UrlText);
                }

                string steamId = dialog.SteamId;

                // If the auto login checkbox was checked, update settings file and global variables.
                if (dialog.AutoLogAccountIndex == true)
                {
                    settingsFile.Write("SelectedAcc", (encryptedAccounts.Count + 1).ToString(), "AutoLog");
                    settingsFile.Write("Selected", "True", "AutoLog");
                    settingsFile.Write("Recent", "False", "AutoLog");
                    selected    = true;
                    recent      = false;
                    selectedAcc = encryptedAccounts.Count + 1;
                }

                try
                {
                    // Encrypt info before saving to file
                    ePassword     = StringCipher.Encrypt(password, eKey);
                    eSharedSecret = StringCipher.Encrypt(sharedSecret, eKey);

                    encryptedAccounts.Add(new Account()
                    {
                        Name = dialog.AccountText, Password = ePassword, SharedSecret = eSharedSecret, ProfUrl = dialog.UrlText, AviUrl = aviUrl, SteamId = steamId, Description = dialog.DescriptionText
                    });

                    Utils.Serialize(encryptedAccounts);

                    RefreshWindow();
                }
                catch (Exception m)
                {
                    MessageBox.Show(m.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);

                    var itemToRemove = encryptedAccounts.Single(r => r.Name == dialog.AccountText);
                    encryptedAccounts.Remove(itemToRemove);

                    Utils.Serialize(encryptedAccounts);

                    NewAccount();
                }
            }
        }
예제 #5
0
        private void PostDeserializedRefresh(bool seedAcc)
        {
            if (encryptedAccounts != null)
            {
                int bCounter = 0;
                int xCounter = 0;
                int yCounter = 0;

                int height = 100;
                int width  = 100;

                double heightOffset = height + (height * 0.2);
                double widthOffset  = width + (width * 0.2);

                // Create new button and textblock for each account
                foreach (var account in encryptedAccounts)
                {
                    string tempPass = StringCipher.Decrypt(account.Password, eKey);

                    if (seedAcc)
                    {
                        string temp2fa = null;
                        string steamId = null;

                        if (account.SharedSecret != null && account.SharedSecret.Length > 0)
                        {
                            temp2fa = StringCipher.Decrypt(account.SharedSecret, eKey);
                        }
                        if (account.SteamId != null && account.SteamId.Length > 0)
                        {
                            steamId = account.SteamId;
                        }

                        decryptedAccounts.Add(new Account()
                        {
                            Name = account.Name, Password = tempPass, SharedSecret = temp2fa, ProfUrl = account.ProfUrl, AviUrl = account.AviUrl, SteamId = steamId, Description = account.Description
                        });
                    }

                    Button    accountButton = new Button();
                    TextBlock accountText   = new TextBlock();

                    accountButton.Style = (Style)Resources["SAMButtonStyle"];

                    accountButton.Tag = bCounter.ToString();

                    //accountButton.Name = account.Name;
                    //accountText.Name = account.Name + "Label";
                    accountText.Text = account.Name;

                    // If there is a description, set up tooltip.
                    if (account.Description != null && account.Description.Length > 0)
                    {
                        accountButton.ToolTip = account.Description;
                    }

                    accountButton.Height = height;
                    accountButton.Width  = width;
                    accountText.Height   = 30;
                    accountText.Width    = 100;

                    accountButton.HorizontalAlignment = HorizontalAlignment.Left;
                    accountButton.VerticalAlignment   = VerticalAlignment.Top;
                    accountText.HorizontalAlignment   = HorizontalAlignment.Left;
                    accountText.VerticalAlignment     = VerticalAlignment.Top;

                    accountButton.Margin = new Thickness(15 + (xCounter * widthOffset), (yCounter * heightOffset) + 14, 0, 0);
                    accountText.Margin   = new Thickness(15 + (xCounter * widthOffset), (yCounter * heightOffset) + 113, 0, 0);

                    accountButton.BorderBrush = null;
                    accountText.Foreground    = new SolidColorBrush(Colors.White);

                    if (account.ProfUrl == "" || account.AviUrl == null || account.AviUrl == "" || account.AviUrl == " ")
                    {
                        accountButton.Content    = account.Name;
                        accountButton.Background = Brushes.LightGray;
                    }
                    else
                    {
                        try
                        {
                            ImageBrush  brush1 = new ImageBrush();
                            BitmapImage image1 = new BitmapImage(new Uri(account.AviUrl));
                            brush1.ImageSource       = image1;
                            accountButton.Background = brush1;
                            buttonGrid.Children.Add(accountText);
                        }
                        catch (Exception m)
                        {
                            // Probably no internet connection or avatar url is bad
                            Console.WriteLine("Error: " + m.Message);

                            accountButton.Content = account.Name;
                        }
                    }

                    buttonGrid.Children.Add(accountButton);

                    accountButton.Click += new RoutedEventHandler(AccountButton_Click);
                    accountButton.PreviewMouseLeftButtonDown += new System.Windows.Input.MouseButtonEventHandler(AccountButton_MouseDown);
                    accountButton.PreviewMouseLeftButtonUp   += new System.Windows.Input.MouseButtonEventHandler(AccountButton_MouseUp);
                    accountButton.MouseLeave += new System.Windows.Input.MouseEventHandler(AccountButton_MouseLeave);

                    ContextMenu accountContext = new ContextMenu();

                    MenuItem deleteItem = new MenuItem();
                    MenuItem editItem   = new MenuItem();
                    MenuItem exportItem = new MenuItem();

                    deleteItem.Header = "Delete";
                    editItem.Header   = "Edit";
                    exportItem.Header = "Export";

                    accountContext.Items.Add(editItem);
                    accountContext.Items.Add(deleteItem);
                    accountContext.Items.Add(exportItem);

                    accountButton.ContextMenu         = accountContext;
                    accountButton.ContextMenuOpening += new ContextMenuEventHandler(ContextMenu_ContextMenuOpening);

                    deleteItem.Click += delegate { DeleteEntry(accountButton); };
                    editItem.Click   += delegate { EditEntry(accountButton); };
                    exportItem.Click += delegate { ExportAccount(Int32.Parse(accountButton.Tag.ToString())); };

                    bCounter++;
                    xCounter++;

                    if ((xCounter % Int32.Parse(accPerRow) == 0) && xCounter != 0)
                    {
                        yCounter++;
                        xCounter = 0;
                    }
                }

                int xVal = 0;
                int newHeight;

                // Adjust window size and info positions
                if (yCounter == 0)
                {
                    xVal              = xCounter + 1;
                    newHeight         = 190;
                    buttonGrid.Height = 141;
                }
                else
                {
                    xVal              = Int32.Parse(accPerRow);
                    newHeight         = 185 + (125 * yCounter);
                    buttonGrid.Height = 141 * (125 + yCounter);
                }

                int newWidth = (xVal * 120) + 25;

                Resize(newHeight, newWidth);
                buttonGrid.Width = newWidth;

                // Adjust new account and export buttons
                Thickness newThickness    = new Thickness(33 + (xCounter * widthOffset), (yCounter * heightOffset) + 52, 0, 0);
                Thickness offsetThickness = new Thickness(33 + (xCounter * widthOffset), (yCounter * heightOffset) + 92, 0, 0);

                NewButton.Margin          = newThickness;
                ExportButton.Margin       = newThickness;
                CancelExportButton.Margin = offsetThickness;
            }
        }
예제 #6
0
        private void ImportButton_Click(object sender, RoutedEventArgs e)
        {
            if (DelimitedAccountsTextBox.Text.Length == 0)
            {
                DelimitedAccountsTextBox.Focus();
                MessageBox.Show("No accounts to import!");
                return;
            }

            if (DelimiterCharacterTextBox.Text.Length == 0)
            {
                DelimiterCharacterTextBox.Focus();
                MessageBox.Show("Delimiter character required!");
                return;
            }

            char   delimiter             = DelimiterCharacterTextBox.Text[0];
            string delimitedAccountsText = DelimitedAccountsTextBox.Text;

            string[] lines = delimitedAccountsText.Split('\n');

            List <Account> accounts = new List <Account>();

            int           sucessful = 0;
            List <string> errors    = new List <string>();

            for (int i = 0; i < lines.Length; i++)
            {
                string line = Regex.Replace(lines[i], @"\s+", string.Empty);

                // Skip empty lines.
                if (line.Length == 0)
                {
                    continue;
                }

                string[] info = line.Split(delimiter);

                // Log account error.
                if (info.Length < 2)
                {
                    errors.Add(line);
                    continue;
                }

                // Shared secret.
                if (info.Length > 2 && info[2] != null && info[2] != string.Empty)
                {
                    accounts.Add(new Account {
                        Name = info[0], Password = StringCipher.Encrypt(info[1], eKey), SharedSecret = StringCipher.Encrypt(info[2], eKey)
                    });
                }
                else
                {
                    accounts.Add(new Account {
                        Name = info[0], Password = StringCipher.Encrypt(info[1], eKey)
                    });
                }

                sucessful++;
            }

            Utils.ImportAccountsFromList(accounts);

            if (errors.Count > 0)
            {
                MessageBox.Show("There were " + errors.Count + " problems with import:\n" + String.Join("\n", errors.ToArray()));
            }

            Close();
        }
예제 #7
0
        private void ImportButton_Click(object sender, RoutedEventArgs e)
        {
            if (DelimitedAccountsTextBox.Text.Length == 0)
            {
                DelimitedAccountsTextBox.Focus();
                MessageBox.Show("No accounts to import!");
                return;
            }

            if (DelimiterCharacterTextBox.Text.Length == 0)
            {
                DelimiterCharacterTextBox.Focus();
                MessageBox.Show("Delimiter character required!");
                return;
            }

            char   delimiter             = DelimiterCharacterTextBox.Text[0];
            string delimitedAccountsText = DelimitedAccountsTextBox.Text;

            string[] lines = delimitedAccountsText.Split('\n');

            List <Account> accounts = new List <Account>();

            foreach (string line in lines)
            {
                string[] info = line.Split(delimiter);

                if (info.Length < 2)
                {
                    MessageBox.Show("Invalid account format!");
                    return;
                }

                // Shared secret.
                if (info.Length > 2 && info[2] != null && info[2] != string.Empty)
                {
                    accounts.Add(new Account {
                        Name = info[0], Password = StringCipher.Encrypt(info[1], eKey), SharedSecret = StringCipher.Encrypt(info[2], eKey)
                    });
                }
                else
                {
                    accounts.Add(new Account {
                        Name = info[0], Password = StringCipher.Encrypt(info[1], eKey)
                    });
                }
            }

            Utils.ImportAccountsFromList(accounts);

            Close();
        }