Beispiel #1
0
        private bool EnsureDatabaseIsCreated()
        {
            filepath = Path.Combine(Application.StartupPath, "dbase.bin");
            if (!File.Exists(filepath))
            {
                using (var dlg = new EnterPasswordDialog())
                {
                    dlg.Text            = "Create Database";
                    dlg.ConfirmPassword = true;

                    if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                    {
                        ProcessEnterPasswordInput(dlg);
                        convoNames = new ConversationNames();
                        SaveConversationNames();
                    }
                    else
                    {
                        // the user did not click "OK", so the database will not be created
                        return(false);
                    }
                }
            }

            return(true);
        }
Beispiel #2
0
        private void ProcessEnterPasswordInput(EnterPasswordDialog dlg)
        {
            string password = dlg.Password;

            InitializeEncryption(password);

            if (dlg.SavePassword)
            {
                SavePassword(password);
            }
        }
Beispiel #3
0
        private bool EnsureEncryptionIsCreated()
        {
            if (encryption == null)
            {
                // has the password been saved?
                var path = appFile.Value;
                if (File.Exists(path))
                {
                    try
                    {
                        var cipher = File.ReadAllBytes(path);
                        var bytes  = ProtectedData.Unprotect(cipher, null, DataProtectionScope.CurrentUser);
                        InitializeEncryption(Encoding.UTF8.GetString(bytes));

                        // the encryption has been initialized, so return
                        return(true);
                    }
                    catch (Exception ex)
                    {
                        // delete the file and fall through
                        MessageBox.Show(this, "Unable to read the saved password because " + ex.Message, "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        File.Delete(path);
                    }
                }

                // if we get here, we need the password so we can initialize the encryption
                using (var dlg = new EnterPasswordDialog())
                {
                    dlg.Text            = "Enter Password";
                    dlg.ConfirmPassword = false;

                    if (dlg.ShowDialog(this) == System.Windows.Forms.DialogResult.OK)
                    {
                        ProcessEnterPasswordInput(dlg);
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }