Example #1
0
        private void btOK_Click(object sender, EventArgs e)
        {
            if (tbPassword.Text != tbRepeat.Text)
            {
                MessageBox.Show("Passwords don't match!",
                    "Check passwords", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            if (mEditMode && tbPassword.Text == mKeyEntry.Password &&
                tbComment.Text == mKeyEntry.Comment)
            {
                DialogResult = System.Windows.Forms.DialogResult.Cancel;
                return; // nothing to save
            }

            KeyEntry newEntry;
            if (mEditMode)
            {
                newEntry = (KeyEntry)mKeyEntry.Clone();
                if (tbPassword.Text.Length > 0)
                    newEntry.Password = tbPassword.Text;
                newEntry.Comment = tbComment.Text;
            }
            else
            {
                if (tbDomain.Text.Length == 0 || tbUser.Text.Length == 0 || tbPassword.Text.Length == 0)
                {
                    MessageBox.Show("Please fill at least Domain, User and Password fields!",
                        "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
                newEntry = new KeyEntry(tbDomain.Text, tbUser.Text, tbPassword.Text, tbComment.Text);
            }

            try
            {
                PasswordDlg pdlg = new PasswordDlg(true);
                if (pdlg.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                    return;
                bool ok = true;
                if (mEditMode)
                    ok = mStorage.ReplaceEntry(mKeyEntry, newEntry, pdlg.Password);
                else
                    ok = mStorage.AddEntry(newEntry, pdlg.Password);

                if (!ok)
                    MessageBox.Show("Operation failed!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception ex)
            {
                string msg = ex.Message;
                if (ex.InnerException != null)
                    msg += "\r\n" + ex.InnerException.Message;
                MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            DialogResult = DialogResult.OK;
        }
Example #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbFilter.Text))
                return;

            if (string.IsNullOrEmpty(mSettings.Filename))
            {
                MessageBox.Show("Please register key storage first!", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            if (mPassword == null)
            {
                PasswordDlg pdlg = new PasswordDlg();
                if (pdlg.ShowDialog(this) != DialogResult.OK || string.IsNullOrEmpty(pdlg.Password))
                    return;
                mPassword = pdlg.Password;
                pdlg.Dispose();
            }
            SetShowPasswords(showPasswordsToolStripMenuItem.Checked);
            SetPasswordTimer();
            EncryptedStorage es = new EncryptedStorage(mSettings.Filename);
            string t = tbFilter.Text.Trim();
            if (tbFilter.Text == "*")
                t = "";
            try
            {
                List<KeyEntry> entries = es.GetEntries(mPassword, t);
                if (entries == null || entries.Count() == 0)
                {
                    ResetStatus();
                    if (entries != null)
                        entries.Clear();
                }
                else
                {
                    lbStatusResults.Text = string.Format("Results: {0}", entries.Count());
                    //if (dt.Rows.Count > 1)
                    //	gridResults.Focus();
                    SetResultsTimer();
                }
                if (entries == null)
                    gridResults.DataSource = mEmptyList;
                else
                    gridResults.DataSource = entries;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                ResetPassword();
            }
        }
Example #3
0
        private void ctxDelete_Click(object sender, EventArgs e)
        {
            KeyEntry entry = GetCurrentKeyEntry();
            if (entry == null) return;

            if (MessageBox.Show("Are you sure you want to delete entry for " + entry.Domain + "?", "Confirm",
                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
            {
                using (PasswordDlg pdlg = new PasswordDlg(true))
                {
                    if (pdlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        EncryptedStorage enc = new EncryptedStorage(mSettings.Filename);
                        try
                        {
                            if (enc.RemoveEntry(entry, pdlg.Password))
                            {
                                MessageBox.Show("Entry has been removed!", "Removed",
                                    MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ResetResults();
                            }
                            else
                                MessageBox.Show("Entry cannot be removed!", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Operation failed!\r\n" + ex.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
            }
        }