Exemple #1
0
        private async void btnImportPasswords_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Title            = "Import Passwords";
            ofd.DefaultExt       = "bpf";
            ofd.Filter           = Globals.Information.AppName + " files (*.bpf)|*.bpf|All files (*.*)|*.*";
            ofd.FilterIndex      = 1;
            ofd.CheckPathExists  = true;
            ofd.RestoreDirectory = true;

            if (ofd.ShowDialog() == DialogResult.OK)
            {
                List <Password> importedPasswords = await BearPassService.Instance().ImportPasswordsAsync(ofd.FileName);

                if (importedPasswords != null)
                {
                    if (Messenger.Confirm("The file contains " + importedPasswords.Count + " passwords. Are you sure you want to import these passwords to your account?"))
                    {
                        try
                        {
                            await PasswordsService.Instance().SaveNewUserPasswordsAsync(user, CryptoService.Instance().DecryptUserPasswords(user, importedPasswords));
                        }
                        catch
                        {
                            Messenger.Show("Unable to import passwords. Either these passwords were encrypted with a different Master Password than yours or you changed your Master Password.", "Error");
                        }
                        ShowPasswords(await PasswordsService.Instance().GetAllUserPasswordsAsync(user));
                    }
                }
            }
        }
Exemple #2
0
        private async void btnExportPasswords_Click(object sender, EventArgs e)
        {
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.Title            = "Export Passwords";
            sfd.DefaultExt       = "bpf";
            sfd.Filter           = Globals.Information.AppName + " files (*.bpf)|*.bpf|All files (*.*)|*.*";
            sfd.FilterIndex      = 1;
            sfd.CheckPathExists  = true;
            sfd.RestoreDirectory = true;

            if (sfd.ShowDialog() == DialogResult.OK)
            {
                if (await BearPassService.Instance().ExportPasswordsAsync(CryptoService.Instance().EncryptUserPasswords(user, user.Passwords), sfd.FileName))
                {
                    Messenger.Show("Passwords exported to " + sfd.FileName + " file.", "Info");
                }
            }
        }