public string getDataByGroup(string value, KeePassLib.PwGroup kpGroup, string kpColumn2Search = "Title", string kpColumn2Return = "Password") { string returnValue = string.Empty; var ioconninfo = new KeePassLib.Serialization.IOConnectionInfo(); if (!(string.IsNullOrEmpty(kpGroup.ToString()))) { try { KeePassLib.PwEntry pw = kpGroup.Entries.FirstOrDefault(i => i.Strings.ReadSafe(kpColumn2Search) == value); if (pw != null) { returnValue = pw.Strings.ReadSafe(kpColumn2Return); } else { returnValue = string.Empty; } pw = null; } catch { throw; } } return(returnValue); }
private void OnCheckGroupClicked(object sender, EventArgs e) { KeePassLib.PwGroup grp = m_host.MainWindow.GetSelectedGroup(); if (grp == null) { return; } PwObjectList <KeePassLib.PwEntry> list = grp.GetEntries(true); CheckEntries(list); }
public KeePassLib.PwGroup getGroup(string name) { KeePassLib.PwGroup group = new KeePassLib.PwGroup(); var ioconninfo = new KeePassLib.Serialization.IOConnectionInfo(); if (!(string.IsNullOrEmpty(KeepassDBFilePath))) { ioconninfo.Path = base64Decode(KeepassDBFilePath); KeePassLib.Keys.CompositeKey compkey = new KeePassLib.Keys.CompositeKey(); if (string.IsNullOrEmpty(KeepassKeyFilePath) && string.IsNullOrEmpty(KeepassMasterPassword)) { throw new Exception("A Key file or Master Password has not been set!"); } else { if (!(string.IsNullOrEmpty(KeepassKeyFilePath))) { compkey.AddUserKey(new KeePassLib.Keys.KcpKeyFile(base64Decode(KeepassKeyFilePath))); } if (!(string.IsNullOrEmpty(KeepassMasterPassword))) { compkey.AddUserKey(new KeePassLib.Keys.KcpPassword(base64Decode(KeepassMasterPassword))); } var db = new KeePassLib.PwDatabase(); try { db.Open(ioconninfo, compkey, null); KeePassLib.Collections.PwObjectList <KeePassLib.PwGroup> groups = db.RootGroup.GetGroups(true); group = groups.First(i => i.Name == name); } catch { throw; } finally { if (db.IsOpen) { db.Close(); db = null; } } } } else { throw new Exception("Keepass DB Path has not been set!"); } return(group); }
private bool IsGroupExpired(KeePassLib.PwGroup pg) { if (pg == null) { return(false); } if (pg.Expires && (pg.ExpiryTime < DateTime.UtcNow)) { return(true); } return(IsGroupExpired(pg.ParentGroup)); }
public string getDataByGroup(string value, string kpGroup, string kpColumn2Search = "Title", string kpColumn2Return = "Password") { KeePassLib.PwGroup group = getGroup(kpGroup); if (group != null) { return(getDataByGroup(value, group, kpColumn2Search, kpColumn2Return)); } else { throw new Exception("Group not found!"); } }
private KeePassLib.PwGroup FindOrCreatePluginGroup() { KeePassLib.PwGroup group = _host.Database.RootGroup.FindGroup(_groupUuid, true); if (ReferenceEquals(group, null)) { group = new KeePassLib.PwGroup(false, true, "Auto Exports", KeePassLib.PwIcon.Disk) { Uuid = _groupUuid, }; _host.Database.RootGroup.AddGroup(group, true); } return(group); }
public static void UpdateUI(bool bRecreateTabBar, KeePass.UI.PwDocument dsSelect, bool bUpdateGroupList, KeePassLib.PwGroup pgSelect, bool bUpdateEntryList, KeePassLib.PwGroup pgEntrySource, bool bSetModified) { //Update entries that are currently shown if (PreserveEntriesShown && !bUpdateEntryList && !bUpdateEntryList) { KeePass.Program.MainForm.RefreshEntriesList(); //bUpdateGroupList = false; //bUpdateEntryList = false; } //Update UI to update all other parts of the UI KeePass.Program.MainForm.UpdateUI(bRecreateTabBar, dsSelect, bUpdateGroupList, bUpdateGroupList ? pgSelect : null, bUpdateEntryList, bUpdateEntryList ? pgEntrySource : null, bSetModified); }
private void OnManageAutoExportClicked(object sender, EventArgs e) { if (ReferenceEquals(_host, null) || ReferenceEquals(_host.Database, null) || !_host.Database.IsOpen) { return; } KeePassLib.Collections.PwObjectList <KeePassLib.PwEntry> entries = new KeePassLib.Collections.PwObjectList <KeePassLib.PwEntry>(); _host.Database.RootGroup.FindEntriesByTag(Tag, entries, true); ExportManager exportManager = new ExportManager(entries.Select(ConvertToExportItem)); exportManager.ShowDialog(); //Remove deleted entry bool hasDelete = false; foreach (KeePassLib.PwEntry entry in entries) { string uuid = entry.Uuid.ToHexString(); if (exportManager.Exports.Any(ei => !string.IsNullOrEmpty(ei.Uuid) && string.Equals(ei.Uuid, uuid, StringComparison.InvariantCultureIgnoreCase))) { continue; } hasDelete = true; KeePassLib.PwDeletedObject deletedObject = new KeePassLib.PwDeletedObject(entry.Uuid, DateTime.Now); _host.Database.DeletedObjects.Add(deletedObject); } //Create new entry bool hasNew = false; KeePassLib.PwGroup savingGroup = FindOrCreatePluginGroup(); foreach (ExportItem exportItem in exportManager.Exports) { if (!string.IsNullOrEmpty(exportItem.Uuid)) { continue; } hasNew = true; KeePassLib.PwEntry newExportEntry = new KeePassLib.PwEntry(true, true); newExportEntry.Strings.Set(KeePassLib.PwDefs.TitleField, new KeePassLib.Security.ProtectedString(false, Path.GetFileName(exportItem.Path.LocalPath))); newExportEntry.Strings.Set(KeePassLib.PwDefs.UrlField, new KeePassLib.Security.ProtectedString(false, exportItem.Path.ToString())); newExportEntry.IconId = KeePassLib.PwIcon.Disk; newExportEntry.Tags = new List <string>() { Tag }; newExportEntry.Strings.Set(KeePassLib.PwDefs.PasswordField, exportItem.Password); savingGroup.AddEntry(newExportEntry, true); } if (hasDelete || hasNew) //Perform action on database { _host.Database.MergeIn(_host.Database, KeePassLib.PwMergeMethod.Synchronize); //Refresh GUI (Event is launched by main UI thread) _host.MainWindow.UpdateUI(false, null, true, savingGroup, true, null, true); _host.MainWindow.RefreshEntriesList(); } }