Example #1
0
        private void BtnNewDB_Click(object sender, EventArgs e)
        {
            using (SaveFileDialog sfd = new SaveFileDialog())
                using (LoginForm login = new LoginForm(true))
                {
                    // Set file extension type to .vault
                    sfd.Filter = "Password Vault (*.vault)|*.vault";

                    // Ask user where they want to create the vault file
                    if (sfd.ShowDialog() == DialogResult.OK &&
                        login.ShowDialog() == DialogResult.OK)
                    {
                        // Ask user for a master password and if they want
                        // Google Authentication protection
                        if (login.EnableGAuth)
                        {
                            using (GAuthForm gAuth = new GAuthForm(Path.GetFileName(sfd.FileName)))
                            {
                                if (gAuth.ShowDialog() == DialogResult.OK)
                                {
                                    // Create new storage object with password and filepath
                                    Program.storage = new Storage(login.Password, sfd.FileName);

                                    // Enable Google Authenticator in storage object
                                    Program.storage.gAuthKey = gAuth.Secret;

                                    // Save to file
                                    FileManager.SaveStorageToFile(Program.storage);

                                    // Enable relevant UI controls and refresh controls
                                    SetLoggedInUI();
                                    RefreshListView();
                                }
                            }
                        }
                        else
                        {
                            // Create new storage object with password and filepath
                            Program.storage = new Storage(login.Password, sfd.FileName);

                            // Save to file
                            FileManager.SaveStorageToFile(Program.storage);

                            // Enable relevant UI controls and refresh controls
                            SetLoggedInUI();
                            RefreshListView();
                        }
                    }
                }
        }
        private void BtnGoogleAuth_Click(object sender, EventArgs e)
        {
            if (_gAuthEnabled)
            {
                // Before removing authenticator, check that they can input a correct PIN
                string userPin = TxtPin.Text.Trim().Replace(" ", "");
                string softPin = GAuth.GeneratePin(Program.storage.gAuthKey);
                if (!softPin.Equals(userPin))
                {
                    // PIN is incorrect
                    MessageBox.Show(this, "Entered PIN is incorrect, please try again.", "Warning!");
                    return;
                }

                // PIN entered was correct, so remove GAuth data from storage object
                Program.storage.gAuthKey = null;

                // Inform user that Google Authenticator has been disabled
                MessageBox.Show(this, "Google Authenticator has been disabled for the current database.\n" +
                                "Please remember to save these changes to file.", "Success!");

                // Show success DialogResult
                DialogResult = DialogResult.OK;
            }
            else
            {
                using (GAuthForm gAuth = new GAuthForm(Path.GetFileName(Program.storage.SessionPath)))
                {
                    if (gAuth.ShowDialog() == DialogResult.OK)
                    {
                        // Enable Google Authenticator in storage object
                        Program.storage.gAuthKey = gAuth.Secret;

                        // Inform the user that Google Authenticator has been enabled
                        MessageBox.Show(this, "Google Authenticator has been enabled for the current database.\n" +
                                        "Please remember to save these changes to file.", "Success!");

                        // Show success DialogResult
                        DialogResult = DialogResult.OK;
                    }
                }
            }
        }