private void newToolStripMenuItem_Click(object sender, EventArgs e) { if (database == null) { database = new SQLiteDatabase(); } if (File.Exists(Properties.Settings.Default.DatabaseFilename)) { if (MessageBox.Show("Are you sure you wish to create a new credential database?\nDoing so will delete the current database and ALL of its data!", "Make New Database", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes) { DeactivateMainForm(); database.DeleteDatabase(); NewPasswordForm newPasswordForm = new NewPasswordForm(); newPasswordForm.ShowDialog(); // Rederive key after getting new password from user CredentialEncryption.DeriveKey(); ActivateMainForm(); } } else { NewPasswordForm newPasswordForm = new NewPasswordForm(); newPasswordForm.ShowDialog(); ActivateMainForm(); } }
private void okButton_Click(object sender, EventArgs e) { if (masterEntryTextBox.Text.Trim().Equals("") || masterConfirmTextBox.Text.Trim().Equals("")) { MessageBox.Show("Password fields cannot be blank.", "Missing Password"); } else { if (masterEntryTextBox.Text.Equals(masterConfirmTextBox.Text)) { database = new SQLiteDatabase(); credentials = database.SelectAllSecureCredentials(); // Decrypt all the usernames and passwords using the old key for (int i = 0; i < credentials.Count; i++) { credentials[i].username = CredentialEncryption.DecryptCredential(credentials[i].username); credentials[i].password = CredentialEncryption.DecryptCredential(credentials[i].password); } string hashString; if (Properties.Settings.Default.UseSHA3Hashing) { IHash hash = HashFactory.Crypto.SHA3.CreateKeccak512(); HashResult hashResult = hash.ComputeString(masterEntryTextBox.Text); hashString = hashResult.ToString(); } else { hashString = PasswordHash.CreateHash(masterEntryTextBox.Text); } database.UpdateHash(hashString); // Update salt? // Put user's password in a secure string for later use SharedObject.encryptedPassword.Clear(); foreach (char c in masterEntryTextBox.Text) { SharedObject.encryptedPassword.AppendChar(c); } // Re-encrypt all the usernames and password using the new key CredentialEncryption.DeriveKey(); for (int i = 0; i < credentials.Count; i++) { credentials[i].username = CredentialEncryption.EncryptCredential(credentials[i].username); credentials[i].password = CredentialEncryption.EncryptCredential(credentials[i].password); database.UpdateSecureCredential(credentials[i], credentials[i].id); } // SharedObject.passwordGood = true; this.Close(); } else { MessageBox.Show("Passwords do not match.", "Mismatched Passwords"); } } }
public void ActivateMainForm() { internetCredential = new Credential(); if (database == null) { database = new SQLiteDatabase(); } CredentialEncryption.DeriveKey(); // Activate window controls categoryTreeView.Visible = true; nameLabel.Visible = true; nameTextBox.Visible = true; usernameLabel.Visible = true; usernameTextBox.Visible = true; passwordLabel.Visible = true; passwordTextBox.Visible = true; urlLabel.Visible = true; urlTextBox.Visible = true; descriptionLabel.Visible = true; descriptionTextBox.Visible = true; searchTextBox.Visible = true; searchButton.Visible = true; // Activate menu controls openToolStripMenuItem.Enabled = false; closeToolStripMenuItem.Enabled = true; saveBackupAsToolStripMenuItem.Enabled = true; changeMasterPasswordToolStripMenuItem.Enabled = true; exportToolStripMenuItem.Enabled = true; lockToolStripMenuItem.Enabled = true; lockToolStripMenuItem.Text = "&Lock"; addCredentialToolStripMenuItem.Enabled = true; editCredentialToolStripMenuItem.Enabled = true; deleteCredentialToolStripMenuItem.Enabled = true; copyUsernameToolStripMenuItem.Enabled = true; copyPasswordToolStripMenuItem.Enabled = true; hideUsernamePasswordToolStripMenuItem.Enabled = true; passwordGeneratorToolStripMenuItem.Enabled = true; goToWebsiteToolStripMenuItem.Enabled = true; optionsToolStripMenuItem.Enabled = true; // Populate treeview allNames = database.SelectCredentialNames(); if (allNames != null) { foreach (string name in allNames) { categoryTreeView.Nodes[0].Nodes.Add(name); } categoryTreeView.ExpandAll(); } // Set all tooltips treeviewToolTip.SetToolTip(categoryTreeView, "Click on a credential record's name to go directly to that record."); searchToolTip.SetToolTip(searchButton, "Enter the name of a credential record to search for."); // Populate fields internetCredential = database.SelectFirstCredential(); if (internetCredential != null) { if (internetCredential.name != null) { idLabel.Text = internetCredential.id.ToString(); nameTextBox.Text = internetCredential.name; usernameTextBox.Text = CredentialEncryption.DecryptCredential(internetCredential.username); passwordTextBox.Text = CredentialEncryption.DecryptCredential(internetCredential.password); urlTextBox.Text = internetCredential.url; descriptionTextBox.Text = internetCredential.description; } } }