Skip to content

Commit

Permalink
Added option to check all passwords in the database
Browse files Browse the repository at this point in the history
  • Loading branch information
mihaifm committed Apr 23, 2019
1 parent 841552a commit 0490110
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 79 deletions.
1 change: 1 addition & 0 deletions HIBPOfflineCheckExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class HIBPOfflineCheckExt : Plugin
private Options options;

private EventHandler<GwmWindowEventArgs> windowAddedHandler;
public HIBPOfflineColumnProv Prov { get { return prov; } }

public override bool Initialize(IPluginHost host)
{
Expand Down
118 changes: 79 additions & 39 deletions HIBPOfflineCheckOptions.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 46 additions & 21 deletions HIBPOfflineCheckOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,34 @@ public HIBPOfflineCheckOptions(HIBPOfflineCheckExt ext)
InitializeComponent();
}

private bool CommitOptions()
{
options.CheckMode = radioButtonOffline.Checked ? Options.CheckModeType.Offline : Options.CheckModeType.Online;
options.HIBPFileName = textBoxFileName.Text;
options.ColumnName = textBoxColumnName.Text;
options.SecureText = textBoxSecureText.Text;
options.InsecureText = textBoxInsecureText.Text;
options.BreachCountDetails = checkBoxBreachCountDetails.Checked;
options.WarningDialog = checkBoxWarningDialog.Checked;
options.WarningDialogText = textBoxWarningDialog.Text;

var standardFields = PwDefs.GetStandardFields();

foreach (string key in standardFields)
{
if (key == options.ColumnName)
{
MessageBox.Show("Column name conflicts with KeePass columns",
" Invalid column name", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}

ext.SaveOptions(options);

return true;
}

private void HIBPOfflineCheckOptions_Load(object sender, EventArgs e)
{
Icon = AppIcons.Default;
Expand Down Expand Up @@ -45,29 +73,10 @@ private void HIBPOfflineCheckOptions_Load(object sender, EventArgs e)

private void buttonOK_Click(object sender, EventArgs e)
{
options.CheckMode = radioButtonOffline.Checked ? Options.CheckModeType.Offline : Options.CheckModeType.Online;
options.HIBPFileName = textBoxFileName.Text;
options.ColumnName = textBoxColumnName.Text;
options.SecureText = textBoxSecureText.Text;
options.InsecureText = textBoxInsecureText.Text;
options.BreachCountDetails = checkBoxBreachCountDetails.Checked;
options.WarningDialog = checkBoxWarningDialog.Checked;
options.WarningDialogText = textBoxWarningDialog.Text;

var standardFields = PwDefs.GetStandardFields();

foreach (string key in standardFields)
if (CommitOptions())
{
if (key == options.ColumnName)
{
MessageBox.Show("Column name conflicts with KeePass columns",
" Invalid column name", MessageBoxButtons.OK, MessageBoxIcon.Error);
return;
}
Close();
}

ext.SaveOptions(options);
Close();
}

private void buttonCancel_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -95,5 +104,21 @@ private void radioButtonOffline_CheckedChanged(object sender, EventArgs e)
{
textBoxFileName.Enabled = radioButtonOffline.Checked;
}

private void buttonCheckAll_Click(object sender, EventArgs e)
{
if (CommitOptions())
{
ext.Prov.CheckAll();
}
}

private void buttonClearAll_Click(object sender, EventArgs e)
{
if (CommitOptions())
{
ext.Prov.ClearAll();
}
}
}
}
52 changes: 52 additions & 0 deletions HIBPOfflineColumnProv.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using KeePassLib;
using KeePassLib.Security;
using System.Net;
using KeePassLib.Collections;

namespace HIBPOfflineCheck
{
Expand Down Expand Up @@ -251,6 +252,9 @@ private void TouchEntry(PwEntry pe)

if (currentStatus == null || currentStatus != Status)
{
pe.Touched -= PwdTouchedHandler;
pe.Touched += PwdTouchedHandler;

pe.Touch(true);
}
}
Expand Down Expand Up @@ -340,6 +344,54 @@ public void PasswordCheckWorker()
}
}

public async void CheckAll()
{
var progressDisplay = new ProgressDisplay();
progressDisplay.Show();

var allEntries = new PwObjectList<PwEntry>();
Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries);

for (uint i = 0; i < allEntries.UCount; i++)
{
PasswordEntry = allEntries.GetAt(i);

await System.Threading.Tasks.Task.Run(() => PasswordCheckWorker());
TouchEntry(PasswordEntry);
progressDisplay.progressBar.Value = ((int) i + 1) * 100 / ((int) allEntries.UCount);

if (progressDisplay.UserTerminated)
{
progressDisplay.Close();
break;
}
}

progressDisplay.Close();
}

public void ClearAll()
{
DialogResult dialog = MessageBox.Show("This will remove the HIBP status for all entries in the database. Continue?",
String.Empty, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);

if (dialog == DialogResult.Cancel)
return;

MainForm mainForm = Host.MainWindow;

PwObjectList<PwEntry> allEntries = new PwObjectList<PwEntry>();
Host.Database.RootGroup.SearchEntries(SearchParameters.None, allEntries);

for (uint i = 0; i < allEntries.UCount; i++)
{
var pwEntry = allEntries.GetAt(i);
pwEntry.Strings.Remove(PluginOptions.ColumnName);
}

mainForm.UpdateUI(false, null, false, null, true, null, true);
}

private async void OnMenuHIBP(object sender, EventArgs e)
{
var progressDisplay = new ProgressDisplay();
Expand Down
4 changes: 2 additions & 2 deletions Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.1.0")]
[assembly: AssemblyFileVersion("1.4.1.0")]
[assembly: AssemblyVersion("1.5.0.0")]
[assembly: AssemblyFileVersion("1.5.0.0")]
Loading

0 comments on commit 0490110

Please sign in to comment.