Example #1
0
        internal static DialogResult ShowDialog(IOConnectionInfo ioInfo,
                                                bool bCreatingNew, out KeyCreationFormResult r)
        {
            bool bSecDesk = (Program.Config.Security.MasterKeyOnSecureDesktop &&
                             ProtectedDialog.IsSupported);

            GFunc <KeyCreationForm> fConstruct = delegate()
            {
                KeyCreationForm f = new KeyCreationForm();
                f.InitEx(ioInfo, bCreatingNew);
                f.SecureDesktopMode = bSecDesk;
                return(f);
            };

            GFunc <KeyCreationForm, KeyCreationFormResult> fResultBuilder = delegate(
                KeyCreationForm f)
            {
                KeyCreationFormResult rEx = new KeyCreationFormResult();
                rEx.CompositeKey     = f.CompositeKey;
                rEx.InvokeAfterClose = f.InvokeAfterClose;
                return(rEx);
            };

            DialogResult dr = ProtectedDialog.ShowDialog <KeyCreationForm,
                                                          KeyCreationFormResult>(bSecDesk, fConstruct, fResultBuilder, out r);

            GAction fIac = ((r != null) ? r.InvokeAfterClose : null);

            if (fIac != null)
            {
                fIac();
            }

            return(dr);
        }
Example #2
0
		private bool ChangeMasterKey(PwDatabase pdOf)
		{
			if(!AppPolicy.Try(AppPolicyId.ChangeMasterKey)) return false;

			PwDatabase pd = (pdOf ?? m_docMgr.ActiveDatabase);
			if((pd == null) || !pd.IsOpen) { Debug.Assert(false); return false; }

			if(!AppPolicy.Current.ChangeMasterKeyNoKey)
			{
				if(!KeyUtil.ReAskKey(pd, true)) return false;
			}

			KeyCreationForm kcf = new KeyCreationForm();
			kcf.InitEx(pd.IOConnectionInfo, false);

			if(UIUtil.ShowDialogNotValue(kcf, DialogResult.OK)) return false; // No UI update

			pd.MasterKey = kcf.CompositeKey;
			pd.MasterKeyChanged = DateTime.Now;

			MessageService.ShowInfoEx(PwDefs.ShortProductName + " - " +
				KPRes.KeyChanged, KPRes.MasterKeyChanged, KPRes.MasterKeyChangedSavePrompt);

			UIUtil.DestroyForm(kcf);
			return true; // No UI update
		}
Example #3
0
        private void OnFileNew(object sender, EventArgs e)
        {
            if(!AppPolicy.Try(AppPolicyId.NewFile)) return;
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
                AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
                AppDefs.FileExtension.FileExt, false, true);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog();
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if(dr != DialogResult.OK) return;

            KeyCreationForm kcf = new KeyCreationForm();
            kcf.InitEx(IOConnectionInfo.FromPath(strPath), true);
            dr = kcf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                UIUtil.DestroyForm(kcf);
                return;
            }

            PwDocument dsPrevActive = m_docMgr.ActiveDocument;
            PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
            pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

            UIUtil.DestroyForm(kcf);

            DatabaseSettingsForm dsf = new DatabaseSettingsForm();
            dsf.InitEx(true, pd);
            dr = dsf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                m_docMgr.CloseDatabase(pd);
                try { m_docMgr.ActiveDocument = dsPrevActive; }
                catch(Exception) { } // Fails if no database is open now
                UpdateUI(false, null, true, null, true, null, false);
                UIUtil.DestroyForm(dsf);
                return;
            }
            UIUtil.DestroyForm(dsf);

            // AutoEnableVisualHiding();

            PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
            pd.RootGroup.AddGroup(pg, true);

            PwEntry pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                KPRes.UserName));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://www.somesite.com/"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                KPRes.Password));
            pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                KPRes.Notes));
            pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
                @"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
            pd.RootGroup.AddEntry(pe, true);

            pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry + " #2"));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                "Michael321"));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://keepass.info/help/kb/kb090406_testform.html"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                "12345"));
            pe.AutoType.Add(new AutoTypeAssociation("Test Form - KeePass*", string.Empty));
            pd.RootGroup.AddEntry(pe, true);

            #if DEBUG
            Random r = Program.GlobalRandom;
            for(uint iSamples = 0; iSamples < 1500; ++iSamples)
            {
                pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

                pe = new PwEntry(true, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                    Guid.NewGuid().ToString()));

                pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

                pg.AddEntry(pe, true);
            }

            pd.CustomData.Set("Sample Custom Data 1", "0123456789");
            pd.CustomData.Set("Sample Custom Data 2", @"µy data");
            #endif

            UpdateUI(true, null, true, null, true, null, true);

            if(this.FileCreated != null)
            {
                FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
                this.FileCreated(this, ea);
            }
        }
Example #4
0
        /// <summary>
        /// Called when [file new].
        /// </summary>
        /// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes. Last reviewed 20150523</remarks>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        internal void CreateNewDatabase()
        {
            if (!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
                AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
                AppDefs.FileExtension.FileExt, false);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog(_host.MainWindow);
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if (dr != DialogResult.OK) return;

            KeePassLib.Keys.CompositeKey key = null;
            KeyCreationSimpleForm kcsf = new KeyCreationSimpleForm();
            bool showUsualKeePassKeyCreationDialog = false;

            // Don't show the simple key creation form if the user has set
            // security policies that restrict the allowable composite key sources
            if (KeePass.Program.Config.UI.KeyCreationFlags == 0)
            {
                kcsf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true);
                dr = kcsf.ShowDialog(_host.MainWindow);
                if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;
                if (dr == DialogResult.No)
                {
                    showUsualKeePassKeyCreationDialog = true;
                }
                else
                {
                    key = kcsf.CompositeKey;
                }
            }
            else
            {
                showUsualKeePassKeyCreationDialog = true;
            }

            if (showUsualKeePassKeyCreationDialog)
            {
                KeyCreationForm kcf = new KeyCreationForm();
                kcf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true);
                dr = kcf.ShowDialog(_host.MainWindow);
                if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;
                key = kcf.CompositeKey;
            }

            PwDocument dsPrevActive = _host.MainWindow.DocumentManager.ActiveDocument;
            PwDatabase pd = _host.MainWindow.DocumentManager.CreateNewDocument(true).Database;
            pd.New(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), key);

            if (!string.IsNullOrEmpty(kcsf.DatabaseName))
            {
                pd.Name = kcsf.DatabaseName;
                pd.NameChanged = DateTime.Now;
            }

            InsertStandardKeePassData(pd);

            InstallKeeFoxSampleEntries(pd, false);

            pd.CustomData.Set("KeePassRPC.KeeFox.configVersion", CurrentConfigVersion);

            // save the new database & update UI appearance
            pd.Save(_host.MainWindow.CreateStatusBarLogger());
            _host.MainWindow.UpdateUI(true, null, true, null, true, null, false);
        }
Example #5
0
		private void OnFileNew(object sender, EventArgs e)
		{
			if(!AppPolicy.Try(AppPolicyId.NewFile)) return;
			if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

			SaveFileDialogEx sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
				KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
				AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
				AppDefs.FileExtension.FileExt, AppDefs.FileDialogContext.Database);

			GlobalWindowManager.AddDialog(sfd.FileDialog);
			DialogResult dr = sfd.ShowDialog();
			GlobalWindowManager.RemoveDialog(sfd.FileDialog);

			string strPath = sfd.FileName;

			if(dr != DialogResult.OK) return;

			KeyCreationForm kcf = new KeyCreationForm();
			kcf.InitEx(IOConnectionInfo.FromPath(strPath), true);
			dr = kcf.ShowDialog();
			if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
			{
				UIUtil.DestroyForm(kcf);
				return;
			}

			PwDocument dsPrevActive = m_docMgr.ActiveDocument;
			PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
			pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

			UIUtil.DestroyForm(kcf);

			DatabaseSettingsForm dsf = new DatabaseSettingsForm();
			dsf.InitEx(true, pd);
			dr = dsf.ShowDialog();
			if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
			{
				m_docMgr.CloseDatabase(pd);
				try { m_docMgr.ActiveDocument = dsPrevActive; }
				catch(Exception) { } // Fails if no database is open now
				UpdateUI(false, null, true, null, true, null, false);
				UIUtil.DestroyForm(dsf);
				return;
			}
			UIUtil.DestroyForm(dsf);

			// AutoEnableVisualHiding();

			PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
			// for(int i = 0; i < 30; ++i) pg.CustomData.Set("Test" + i.ToString("D2"), "12345");
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
			// pg.CustomData.Set("GroupTestItem", "TestValue");
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
			pd.RootGroup.AddGroup(pg, true);

			pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
			pd.RootGroup.AddGroup(pg, true);

			PwEntry pe = new PwEntry(true, true);
			pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
				KPRes.SampleEntry));
			pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
				KPRes.UserName));
			pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
				PwDefs.HomepageUrl));
			pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
				KPRes.Password));
			pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
				KPRes.Notes));
			pe.AutoType.Add(new AutoTypeAssociation(KPRes.TargetWindow,
				@"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}"));
			// for(int i = 0; i < 30; ++i) pe.CustomData.Set("Test" + i.ToString("D2"), "12345");
			pd.RootGroup.AddEntry(pe, true);

			pe = new PwEntry(true, true);
			pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
				KPRes.SampleEntry + " #2"));
			pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
				"Michael321"));
			pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
				@"http://keepass.info/help/kb/testform.html"));
			pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
				"12345"));
			pe.AutoType.Add(new AutoTypeAssociation("*Test Form - KeePass*", string.Empty));
			pd.RootGroup.AddEntry(pe, true);

#if DEBUG
			Random r = Program.GlobalRandom;
			long lTimeMin = (new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc)).ToBinary();
			long lTimeMax = (new DateTime(2030, 11, 25, 11, 58, 58, DateTimeKind.Utc)).ToBinary();
			Debug.Assert(lTimeMin < lTimeMax);
			PwProfile prf = new PwProfile();
			prf.CharSet = new PwCharSet(PwCharSet.UpperCase + PwCharSet.LowerCase +
				PwCharSet.Digits + PwCharSet.PrintableAsciiSpecial);
			prf.GeneratorType = PasswordGeneratorType.CharSet;
			for(uint iSamples = 0; iSamples < 1500; ++iSamples)
			{
				pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

				pe = new PwEntry(true, true);

				ProtectedString ps;
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
					ps.ReadString()));
				PwGenerator.Generate(out ps, prf, null, null);
				pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
					ps.ReadString()));

				pe.CreationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LastModificationTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LastAccessTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.ExpiryTime = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));
				pe.LocationChanged = DateTime.FromBinary(lTimeMin + (long)(r.NextDouble() *
					(lTimeMax - lTimeMin)));

				pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

				pg.AddEntry(pe, true);
			}

			pd.CustomData.Set("Sample Custom Data 1", "0123456789");
			pd.CustomData.Set("Sample Custom Data 2", "\u00B5y data");

			// pd.PublicCustomData.SetString("Sample Custom Data", "Sample Value");
#endif

			UpdateUI(true, null, true, null, true, null, true);

			if(this.FileCreated != null)
			{
				FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
				this.FileCreated(this, ea);
			}
		}
Example #6
0
        /// <summary>
        /// Called when [file new].
        /// </summary>
        /// <remarks>Review whenever private KeePass.MainForm.OnFileNew method changes.</remarks>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        internal void CreateNewDatabase()
        {
            if (!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter(
                AppDefs.FileExtension.FileExt, KPRes.KdbxFiles, true), 1,
                AppDefs.FileExtension.FileExt, false);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog(_host.MainWindow);
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if (dr != DialogResult.OK) return;

            KeePassLib.Keys.CompositeKey key;
            KeyCreationSimpleForm kcsf = new KeyCreationSimpleForm();
            kcsf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true);
            dr = kcsf.ShowDialog(_host.MainWindow);
            if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;
            if (dr == DialogResult.No)
            {
                KeyCreationForm kcf = new KeyCreationForm();
                kcf.InitEx(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), true);
                dr = kcf.ShowDialog(_host.MainWindow);
                if ((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;
                key = kcf.CompositeKey;
            } else
            {
                key = kcsf.CompositeKey;
            }

            PwDocument dsPrevActive = _host.MainWindow.DocumentManager.ActiveDocument;
            PwDatabase pd = _host.MainWindow.DocumentManager.CreateNewDocument(true).Database;
            pd.New(KeePassLib.Serialization.IOConnectionInfo.FromPath(strPath), key);

            if (!string.IsNullOrEmpty(kcsf.DatabaseName))
            {
                pd.Name = kcsf.DatabaseName;
                pd.NameChanged = DateTime.Now;
            }

            InsertStandardKeePassData(pd);

            InstallKeeFoxSampleEntries(pd);

            // save the new database & update UI appearance
            pd.Save(_host.MainWindow.CreateStatusBarLogger());
            _host.MainWindow.UpdateUI(true, null, true, null, true, null, false);
        }
Example #7
0
        private void OnFileNew(object sender, EventArgs e)
        {
            if(!AppPolicy.Try(AppPolicyId.SaveFile)) return;

            // OnFileClose(sender, e);
            // if(m_pwDatabase.IsOpen) return;

            SaveFileDialog sfd = UIUtil.CreateSaveFileDialog(KPRes.CreateNewDatabase,
                KPRes.NewDatabaseFileName, UIUtil.CreateFileTypeFilter("kdbx",
                KPRes.KdbxFiles, true), 1, "kdbx", false);

            GlobalWindowManager.AddDialog(sfd);
            DialogResult dr = sfd.ShowDialog();
            GlobalWindowManager.RemoveDialog(sfd);

            string strPath = sfd.FileName;

            if(dr != DialogResult.OK) return;

            KeyCreationForm kcf = new KeyCreationForm();
            kcf.InitEx(true, strPath);
            dr = kcf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort)) return;

            DocumentStateEx dsPrevActive = m_docMgr.ActiveDocument;
            PwDatabase pd = m_docMgr.CreateNewDocument(true).Database;
            pd.New(IOConnectionInfo.FromPath(strPath), kcf.CompositeKey);

            DatabaseSettingsForm dsf = new DatabaseSettingsForm();
            dsf.InitEx(true, pd);
            dr = dsf.ShowDialog();
            if((dr == DialogResult.Cancel) || (dr == DialogResult.Abort))
            {
                m_docMgr.CloseDatabase(pd);
                m_docMgr.ActiveDocument = dsPrevActive;
                UpdateUI(false, null, true, null, true, null, false);
                return;
            }

            AutoEnableVisualHiding();

            PwGroup pg = new PwGroup(true, true, KPRes.General, PwIcon.Folder);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.WindowsOS, PwIcon.DriveWindows);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Network, PwIcon.NetworkServer);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Internet, PwIcon.World);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.EMail, PwIcon.EMail);
            pd.RootGroup.AddGroup(pg, true);

            pg = new PwGroup(true, true, KPRes.Homebanking, PwIcon.Homebanking);
            pd.RootGroup.AddGroup(pg, true);

            PwEntry pe = new PwEntry(true, true);
            pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                KPRes.SampleEntry));
            pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                KPRes.UserName));
            pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                @"http://www.somesite.com/"));
            pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                KPRes.Password));
            pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                KPRes.Notes));
            pe.AutoType.Set(KPRes.TargetWindow, @"{USERNAME}{TAB}{PASSWORD}{TAB}{ENTER}");
            pd.RootGroup.AddEntry(pe, true);

            #if DEBUG
            Random r = Program.GlobalRandom;
            for(uint iSamples = 0; iSamples < 1500; ++iSamples)
            {
                pg = pd.RootGroup.Groups.GetAt(iSamples % 5);

                pe = new PwEntry(true, true);

                pe.Strings.Set(PwDefs.TitleField, new ProtectedString(pd.MemoryProtection.ProtectTitle,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UserNameField, new ProtectedString(pd.MemoryProtection.ProtectUserName,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.UrlField, new ProtectedString(pd.MemoryProtection.ProtectUrl,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.PasswordField, new ProtectedString(pd.MemoryProtection.ProtectPassword,
                    Guid.NewGuid().ToString()));
                pe.Strings.Set(PwDefs.NotesField, new ProtectedString(pd.MemoryProtection.ProtectNotes,
                    Guid.NewGuid().ToString()));

                pe.IconId = (PwIcon)r.Next(0, (int)PwIcon.Count);

                pg.AddEntry(pe, true);
            }
            #endif

            UpdateUI(true, null, true, null, true, null, true);

            if(this.FileCreated != null)
            {
                FileCreatedEventArgs ea = new FileCreatedEventArgs(pd);
                this.FileCreated(this, ea);
            }
        }
Example #8
0
        private void OnFileChangeMasterKey(object sender, EventArgs e)
        {
            PwDatabase pd = m_docMgr.ActiveDatabase;

            KeyCreationForm kcf = new KeyCreationForm();
            kcf.InitEx(false, pd.IOConnectionInfo.GetDisplayName());
            if(kcf.ShowDialog() == DialogResult.OK)
            {
                pd.MasterKey = kcf.CompositeKey;
                MessageService.ShowInfo(KPRes.MasterKeyChanged, KPRes.MasterKeyChangedSavePrompt);
            }

            UpdateUIState(true);
        }