private bool CheckEncryption()
      {
         _encryptionLabel.Visible = true;
         Application.DoEvents();

         bool success = false;

         using (WaitCursor wait = new WaitCursor())
         {
            bool encrypted = PDFFile.IsEncrypted(_fileName);

            _encryptionValueLabel.Visible = true;
            _encryptionValueLabel.Text = encrypted ? DemosGlobalization.GetResxString(GetType(), "resx_Encrypted") : DemosGlobalization.GetResxString(GetType(), "resx_NotEncrypted");
            Application.DoEvents();

            if (encrypted)
            {
               using (GetPasswordDialog dlg = new GetPasswordDialog())
               {
                  if (dlg.ShowDialog(this) == DialogResult.OK)
                  {
                     success = true;
                     _password = dlg.Password;
                  }
               }
            }
            else
            {
               success = true;
            }
         }

         return success;
      }
예제 #2
0
        private void ValidateConnection()
        {
            var connectionString = string.Format("Data Source={0}", m_storePath);

            if (m_firstConnection)
            {
                var connection = new SqlCeConnection(connectionString);

                // see if we need a password
                try
                {
                    connection.Open();
                }
                catch (SqlCeException ex)
                {
                    if (ex.NativeError == 25028)
                    {
                        // a password is required.
                        var dialog = new GetPasswordDialog();
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            connectionString           += (";password=" + dialog.Password);
                            connection.ConnectionString = connectionString;
                            try
                            {
                                connection.Open();
                            }
                            catch (SqlCeException exi)
                            {
                                if (exi.NativeError == 25028)
                                {
                                    throw new InvalidPasswordException();
                                }

                                throw;
                            }
                        }
                        else
                        {
                            throw new InvalidPasswordException();
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                finally
                {
                    if (connection != null)
                    {
                        connection.Dispose();
                    }
                }

                m_connectionString = connectionString;
                m_firstConnection  = false;
            }
        }
        internal static void TmpInstance_NeedConstringPassword(object sender, DoormatBot.Helpers.PersonalSettings.GetConstringPWEventArgs e)
        {
            if (!string.IsNullOrWhiteSpace(dbPw))
            {
                e.Password = dbPw;
                return;
            }

            GetPasswordDialog tmpdiag = new GetPasswordDialog();

            if (tmpdiag.ShowDialog() ?? false)
            {
                dbPw = e.Password = tmpdiag.Pw;
            }
        }