Skip to content

Commit

Permalink
Add configurable good news hint
Browse files Browse the repository at this point in the history
Resolves #7
  • Loading branch information
kapsiR committed May 1, 2020
1 parent a53ffca commit 1a8a048
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
## Added
- Added a new option to enable a good news (no breach) message, when an entry is manually checked ('check current password')

## [0.5.0] - 2020-04-26
### Added
Expand Down
30 changes: 28 additions & 2 deletions HaveIBeenPwnedKeePassPlugin/HaveIBeenPwnedPluginExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ public sealed class HaveIBeenPwnedPluginExt : Plugin
private IPluginHost _pluginHost = null;
private bool _checkPasswordOnEntryTouched = true;
private bool _isIgnoreExpiredEntriesEnabled = true;
private bool _isShowGoodNewsOnManualEntryCheckEnabled = false;
private const string Option_CheckPasswordOnEntryTouched = "HaveIBeenPwnedPlugin_Option_CheckPasswordOnEntryTouched";
private const string Option_IgnoreExpiredEntries = "HaveIBeenPwnedPlugin_Option_IgnoreExpiredEntries";
private const string Option_ShowGoodNewsOnManualEntryCheck = "HaveIBeenPwnedPlugin_Option_ShowGoodNewsOnManualEntryCheck";
private const string BreachedTag = "pwned";
private const string BreachCountCustomDataName = "pwned-count";
private readonly HIBP _hibp;
Expand Down Expand Up @@ -72,6 +74,7 @@ private void InitializeCustomConfigSettings()
{
_checkPasswordOnEntryTouched = _pluginHost.CustomConfig.GetBool(Option_CheckPasswordOnEntryTouched, true);
_isIgnoreExpiredEntriesEnabled = _pluginHost.CustomConfig.GetBool(Option_IgnoreExpiredEntries, true);
_isShowGoodNewsOnManualEntryCheckEnabled = _pluginHost.CustomConfig.GetBool(Option_ShowGoodNewsOnManualEntryCheck, false);
}

private async void PwEntry_TouchedAsync(object o, ObjectTouchedEventArgs e)
Expand All @@ -92,7 +95,7 @@ private async void PwEntry_TouchedAsync(object o, ObjectTouchedEventArgs e)
}
}

private async Task CheckHaveIBeenPwnedForEntry(PwEntry pwEntry)
private async Task CheckHaveIBeenPwnedForEntry(PwEntry pwEntry, Action executesWhenEntryIsGood = null)
{
if (pwEntry == null)
{
Expand All @@ -116,6 +119,7 @@ private async Task CheckHaveIBeenPwnedForEntry(PwEntry pwEntry)
else
{
entryModified = UpdateEntryRemoveBreachInformation(pwEntry);
executesWhenEntryIsGood?.Invoke();
}

UpdateUI_EntryList(entryModified);
Expand Down Expand Up @@ -195,6 +199,7 @@ private void SaveCurrentCustomConfigSettings()
{
_pluginHost.CustomConfig.SetBool(Option_CheckPasswordOnEntryTouched, _checkPasswordOnEntryTouched);
_pluginHost.CustomConfig.SetBool(Option_IgnoreExpiredEntries, _isIgnoreExpiredEntriesEnabled);
_pluginHost.CustomConfig.SetBool(Option_ShowGoodNewsOnManualEntryCheck, _isShowGoodNewsOnManualEntryCheckEnabled);
}

public override ToolStripMenuItem GetMenuItem(PluginMenuType t)
Expand Down Expand Up @@ -239,9 +244,23 @@ public override ToolStripMenuItem GetMenuItem(PluginMenuType t)
checkBoxMenuItem_Option_SkipExpiredEntries.Click += CheckBoxMenuItem_Option_SkipExpiredEntries_Click;
pluginRootMenuItem.DropDownItems.Add(checkBoxMenuItem_Option_SkipExpiredEntries);

ToolStripMenuItem checkBoxMenuItem_Option_ShowGoodNewsOnManualEntryCheck = new ToolStripMenuItem
{
Text = "Show good news when checking an entry manually too",
Checked = _isShowGoodNewsOnManualEntryCheckEnabled
};
checkBoxMenuItem_Option_ShowGoodNewsOnManualEntryCheck.Click += CheckBoxMenuItem_Option_ShowGoodNewsOnManualEntryCheck_Click;
pluginRootMenuItem.DropDownItems.Add(checkBoxMenuItem_Option_ShowGoodNewsOnManualEntryCheck);

return pluginRootMenuItem;
}

private void CheckBoxMenuItem_Option_ShowGoodNewsOnManualEntryCheck_Click(object sender, EventArgs e)
{
_isShowGoodNewsOnManualEntryCheckEnabled = !_isShowGoodNewsOnManualEntryCheckEnabled;
UIUtil.SetChecked(sender as ToolStripMenuItem, _isShowGoodNewsOnManualEntryCheckEnabled);
}

private void CheckBoxMenuItem_Option_SkipExpiredEntries_Click(object sender, EventArgs e)
{
_isIgnoreExpiredEntriesEnabled = !_isIgnoreExpiredEntriesEnabled;
Expand All @@ -256,7 +275,14 @@ private async void CheckCurrentPasswordMenuItem_ClickAsync(object sender, EventA

if (selectedEntry != null)
{
await CheckHaveIBeenPwnedForEntry(selectedEntry);
await CheckHaveIBeenPwnedForEntry(selectedEntry, () =>
{
if (_isShowGoodNewsOnManualEntryCheckEnabled)
{
MessageService.ShowInfoEx("Good news", $"No pwnage found!",
$"Source: https://haveibeenpwned.com");
}
});
}
else
{
Expand Down

0 comments on commit 1a8a048

Please sign in to comment.