Ejemplo n.º 1
0
 private void searchButton_Click(object sender, EventArgs e)
 {
     if (searchTextBox.Text.Length > 0)
     {
         internetCredential = database.SearchCredentialByName(searchTextBox.Text);
         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;
             }
         }
         else
         {
             MessageBox.Show("No result found.", "No Results");
         }
     }
     else
     {
         MessageBox.Show("Search field cannot be empty.", "Missing Search Text");
     }
 }
Ejemplo n.º 2
0
        private void exportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            List <Credential> allCredentials;
            Stream            stream;
            StreamWriter      streamWriter;

            if (exportSaveFileDialog.ShowDialog() == DialogResult.OK)
            {
                allCredentials = database.SelectAllCredentials();

                stream       = (Stream)exportSaveFileDialog.OpenFile();
                streamWriter = new StreamWriter(stream);

                // Write the full credential record to the file
                foreach (Credential internetCredential in allCredentials)
                {
                    streamWriter.WriteLine("Name: " + internetCredential.name + "\r\nUsername: "******"\r\nPassword: "******"\r\nURL: " + internetCredential.url
                                           + "\r\nDescription: " + internetCredential.description + "\r\n");
                }

                streamWriter.Close();
                stream.Close();
            }
        }
Ejemplo n.º 3
0
        private void categoryTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Equals(categoryTreeView.Nodes[0]))
            {
                // Don't do anything if the root element was clicked
            }
            else
            {
                // Get the text of the child node that has been clicked
                internetCredential = database.SelectCredentialByName(e.Node.Text);

                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;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        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 (nameTextBox.Text.Length < 1)
            {
                MessageBox.Show("Name cannot be blank.", "Missing Credential Name");
            }
            else if (usernameTextBox.Text.Length < 1)
            {
                MessageBox.Show("Username cannot be blank.", "Missing Credential Username");
            }
            else if (passwordTextBox.Text.Length < 1)
            {
                MessageBox.Show("Password cannot be blank.", "Missing Credential Password");
            }
            else
            {
                if (MessageBox.Show("Save changes to this credential?", "Save Credential Changes", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    database = new SQLiteDatabase();

                    internetCredential.name        = nameTextBox.Text;
                    internetCredential.username    = CredentialEncryption.EncryptCredential(usernameTextBox.Text);
                    internetCredential.password    = CredentialEncryption.EncryptCredential(passwordTextBox.Text);
                    internetCredential.url         = urlTextBox.Text;
                    internetCredential.description = descriptionTextBox.Text;

                    database.UpdateInternetCredential(internetCredential, internetCredential.id);

                    MessageBox.Show("New credential information saved.", "Changes Saved");
                    // Bypass the form closing event since the user already pressed the ok button
                    userAlreadyClosing = true;
                    this.Close();
                }
            }
        }
        private void EditCredentialForm_Load(object sender, EventArgs e)
        {
            encryptCredential = new CredentialEncryption();

            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;
        }
Ejemplo n.º 7
0
        private void MainForm_Activated(object sender, EventArgs e)
        {
            Application.Idle += new EventHandler(Application_Idle);

            // Place the generated password into the password field when the users confirms copying it in the password generator
            if (SharedObject.generatedPassword.Length > 0)
            {
                passwordTextBox.Text           = SharedObject.generatedPassword;
                SharedObject.generatedPassword = "";

                internetCredential.id          = Convert.ToInt32(idLabel.Text);
                internetCredential.name        = nameTextBox.Text;
                internetCredential.username    = CredentialEncryption.EncryptCredential(usernameTextBox.Text);
                internetCredential.password    = CredentialEncryption.EncryptCredential(passwordTextBox.Text);
                internetCredential.url         = urlTextBox.Text;
                internetCredential.description = descriptionTextBox.Text;

                database.UpdateInternetCredential(internetCredential, internetCredential.id);
            }
            else if (SharedObject.newCredentialAdded)
            {
                SharedObject.newCredentialAdded = false;

                // Depopulate treeview and then repopuate it with the new record
                categoryTreeView.Nodes[0].Nodes.Clear();
                allNames = database.SelectCredentialNames();
                if (allNames != null)
                {
                    foreach (string name in allNames)
                    {
                        categoryTreeView.Nodes[0].Nodes.Add(name);
                    }
                    categoryTreeView.ExpandAll();
                }

                // Show the recently added record to the user
                internetCredential = database.SelectInternetCredential(database.CountCredentials());
                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;
                    }
                }
            }
        }
Ejemplo n.º 8
0
 private void nextButton_Click(object sender, EventArgs e)
 {
     internetCredential = database.SelectInternetCredential(Convert.ToInt32(idLabel.Text) + 1);
     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;
         }
     }
 }
Ejemplo n.º 9
0
        private void editCredentialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Length > 0)
            {
                internetCredential.id          = Convert.ToInt32(idLabel.Text);
                internetCredential.name        = nameTextBox.Text;
                usernameTextBox.Text           = CredentialEncryption.DecryptCredential(internetCredential.username);
                passwordTextBox.Text           = CredentialEncryption.DecryptCredential(internetCredential.password);
                internetCredential.url         = urlTextBox.Text;
                internetCredential.description = descriptionTextBox.Text;

                EditCredentialForm editCredentialForm = new EditCredentialForm(internetCredential);
                editCredentialForm.ShowDialog();
            }
            else
            {
                MessageBox.Show("No credential exists to be edited.", "No Credential");
            }
        }
Ejemplo n.º 10
0
        private void deleteCredentialToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Length > 0)
            {
                if (MessageBox.Show("Do you wish to delete this credential?\nThis data cannot be recovered once it is deleted.", "Delete Credential", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    database.DeleteInternetCredential(Convert.ToInt32(idLabel.Text));

                    // Depopulate treeview and then repopuate it with the new record
                    categoryTreeView.Nodes[0].Nodes.Clear();
                    allNames = database.SelectCredentialNames();
                    if (allNames != null)
                    {
                        foreach (string name in allNames)
                        {
                            categoryTreeView.Nodes[0].Nodes.Add(name);
                        }
                        categoryTreeView.ExpandAll();
                    }

                    // 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;
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("No credential exists to be deleted.", "No Credential");
            }
        }
        private void okButton_Click(object sender, EventArgs e)
        {
            if (nameTextBox.Text.Length < 1)
            {
                MessageBox.Show("Name cannot be blank.", "Missing Credential Name");
            }
            else if (usernameTextBox.Text.Length < 1)
            {
                MessageBox.Show("Username cannot be blank.", "Missing Credential Username");
            }
            else if (passwordTextBox.Text.Length < 1)
            {
                MessageBox.Show("Password cannot be blank.", "Missing Credential Password");
            }
            else
            {
                if (MessageBox.Show("Add this credential to the database?", "Add New Credential", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    internetCredential = new Credential();
                    database           = new SQLiteDatabase();
                    encryptCredential  = new CredentialEncryption();

                    internetCredential.name        = nameTextBox.Text;
                    internetCredential.username    = CredentialEncryption.EncryptCredential(usernameTextBox.Text);
                    internetCredential.password    = CredentialEncryption.EncryptCredential(passwordTextBox.Text);
                    internetCredential.url         = urlTextBox.Text;
                    internetCredential.description = descriptionTextBox.Text;

                    database.InsertInternetCredential(internetCredential);

                    MessageBox.Show("Credential added to the database.", "Credential Added");
                    SharedObject.newCredentialAdded = true;
                    // Bypass the form closing event since the user already pressed the ok button
                    userAlreadyClosing = true;
                    this.Close();
                }
            }
        }
        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");
                }
            }
        }
Ejemplo n.º 13
0
        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;
                }
            }
        }
Ejemplo n.º 14
0
        private void categoryTreeView_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Left)
            {
                // Stop the control from registering the left key press
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Right)
            {
                // Stop the control from registering the right key press
                e.Handled = true;
            }
            else if (e.KeyCode == Keys.Up)
            {
                if (categoryTreeView.SelectedNode.Equals(categoryTreeView.Nodes[0]))
                {
                    // Don't do anything if the root element was selected
                }
                else
                {
                    // Get the text of the child node that has been selected
                    internetCredential = database.SelectCredentialByName(categoryTreeView.SelectedNode.Text);

                    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;
                        }
                    }
                }
            }
            else if (e.KeyCode == Keys.Down)
            {
                if (categoryTreeView.SelectedNode.Equals(categoryTreeView.Nodes[0]))
                {
                    // Don't do anything if the root element was selected
                }
                else
                {
                    // Get the text of the child node that has been selected
                    internetCredential = database.SelectCredentialByName(categoryTreeView.SelectedNode.Text);

                    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;
                        }
                    }
                }
            }
        }