private void buttonLogin_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         bool CorrectLogin = (textBoxLogin.Text.Length > 5 && textBoxLogin.Text.Length < 50 && textBoxLogin.Text.Contains('@')),
             CorrectPassword = (textBoxPassword.Password.Length > 3 && textBoxPassword.Password.Length < 50);
         int count = -1;
         if (CorrectLogin && CorrectPassword)
         {
             try
             {
                 myCon = new Imap(textBoxLogin.Text, textBoxPassword.Password);
                 myCon.Connection();
                 count = myCon.Connections.Inbox.Count;
             }
             catch (Exception ex)
             {
                 //MessageBox.Show(ex.ToString());
                 MessageBox.Show("Подключение не удалось. Проверьте правильность данных и наличие интернет соединения.");
             }
         }
         else
         {
             MessageBox.Show("Ваши данные некорректны");
         }
         if (Edit)
         {
             clientDB.UpdateEmail(Cryptography.Encrypt(OldEmail), Cryptography.Encrypt(textBoxLogin.Text), Cryptography.Encrypt(textBoxPassword.Password));
             this.Close();
         }
         else
         {
             bool NeedIt = true;
             if (count != -1)
             {
                 if (clientDB.DisplayAllUsers().Count != 0)
                 {
                     if (clientDB.DisplayAllUsers().Contains(Cryptography.Encrypt(textBoxLogin.Text)))
                         NeedIt = false;
                 }
                 if (NeedIt)
                 {
                     clientDB.InsertUser(Cryptography.Encrypt(textBoxLogin.Text), Cryptography.Encrypt(textBoxPassword.Password), true);
                     if (firstLogin)
                     {
                         this.Hide();
                         Tray myTray = new Tray();
                         firstLogin = false;
                     }
                     else
                         this.Close();
                 }
                 else
                 {
                     MessageBox.Show("Такой адрес уже есть");
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.ToString());
     }
 }
 private void Auth()
 {
     try
     {
         GlobalSettings.LoadSettings();
     }
     catch //(Exception ex)
     {
         //MessageBox.Show(ex.ToString());
     }
     var allUsers = clientDB.DisplayAllUsers();
     if (allUsers.Count != 0)
     {
         var clAllAcs = clientDB.AllAccount();
         myCon = new Imap(Cryptography.Decrypt(allUsers[0]), Cryptography.Decrypt(clAllAcs[allUsers[0]]));
         try
         {
             myCon.Connection();
             if (firstLogin)
             {
                 Tray myTray = new Tray();
                 firstLogin = false;
             }
         }
         catch (Exception ex)
         {
             //MessageBox.Show(ex.ToString());
             this.Show();
         }
     }
     else
     {
         this.Show();
     }
 }