Skip to content

Commit

Permalink
Adding option to copy password to clipboard on fingerprint scan
Browse files Browse the repository at this point in the history
  • Loading branch information
gazugafan committed Dec 6, 2020
1 parent 3699364 commit f8ca6e8
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 29 deletions.
2 changes: 1 addition & 1 deletion FingerPassSetup/Product.wxs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension"><?define fingerpass_TargetDir=$(var.fingerpass.TargetDir)?><?define messages_TargetDir=$(var.messages.TargetDir)?><?define fingerpass_service_TargetDir=$(var.fingerpass_service.TargetDir)?><?define WinBioNET_TargetDir=$(var.WinBioNET.TargetDir)?><?define NetFx472MinRelease = 461808 ?>

<Product Id="d8219647-c1d3-4a10-b719-075bc08d3895" Name="FingerPass" Language="1033" Version="1.0.0.0" Manufacturer="gazugafan" UpgradeCode="5d4bb806-c91a-4e53-aa21-d5540284d3dc">
<Product Id="d8219647-c1d3-4a10-b719-075bc08d3895" Name="FingerPass" Language="1033" Version="1.1.0.0" Manufacturer="gazugafan" UpgradeCode="5d4bb806-c91a-4e53-aa21-d5540284d3dc">

<Package Description="A fingerprint-enabled password manager" InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

Expand Down
31 changes: 19 additions & 12 deletions fingerpass/DatabaseForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,21 +43,24 @@ private void DatabaseForm_Load(object sender, EventArgs e)
{
this.FormBorderStyle = FormBorderStyle.FixedDialog; //some DPI madness requires this to be set to sizable to start

int[] widths = new int[5];
widths[0] = 25;
widths[1] = 25;
widths[2] = 25;
int[] widths = new int[6];
widths[0] = 20;
widths[1] = 20;
widths[2] = 20;
widths[3] = 15;
widths[4] = 10;
widths[4] = 15;
widths[5] = 10;

passwordsDataGrid.Columns.Add("programNameColumn", "Program Name");
passwordsDataGrid.Columns.Add("windowTitleColumn", "Window Title");
passwordsDataGrid.Columns.Add("passwordColumn", "Password");
passwordsDataGrid.Columns.Add(new DataGridViewCheckBoxColumn());
passwordsDataGrid.Columns.Add(new DataGridViewCheckBoxColumn());
passwordsDataGrid.Columns.Add(new DataGridViewLinkColumn());

passwordsDataGrid.Columns[3].HeaderText = "Press Enter?";
passwordsDataGrid.Columns[4].HeaderText = "Actions";
passwordsDataGrid.Columns[4].HeaderText = "Just Copy?";
passwordsDataGrid.Columns[5].HeaderText = "Actions";

//set column widths based on percents, and other options...
passwordsDataGrid.RowHeadersWidth = 50;
Expand Down Expand Up @@ -86,6 +89,7 @@ private void DatabaseForm_Load(object sender, EventArgs e)
row.Cells[1].Value = _newWindowTitle;
row.Cells[2].Value = "";
row.Cells[3].Value = true;
row.Cells[4].Value = false;

row.Cells[2].Selected = true;
passwordsDataGrid.BeginEdit(true);
Expand Down Expand Up @@ -164,6 +168,7 @@ private void UpdatePasswordsList()
row.Cells.Add(new DataGridViewTextBoxCell());
row.Cells.Add(new DataGridViewTextBoxCell());
row.Cells.Add(new DataGridViewCheckBoxCell());
row.Cells.Add(new DataGridViewCheckBoxCell());
row.Cells.Add(new DataGridViewLinkCell());
updatePasswordCells(row, password);

Expand All @@ -186,9 +191,10 @@ private void updatePasswordCells(DataGridViewRow row, Password password)
row.Cells[1].Value = password.Title;
row.Cells[2].Value = defaultPassword;
row.Cells[3].Value = password.PressEnter;
row.Cells[4].Value = "Delete";
(row.Cells[4] as DataGridViewLinkCell).LinkBehavior = LinkBehavior.HoverUnderline;
(row.Cells[4] as DataGridViewLinkCell).TrackVisitedState = false;
row.Cells[4].Value = password.UseClipboard;
row.Cells[5].Value = "Delete";
(row.Cells[5] as DataGridViewLinkCell).LinkBehavior = LinkBehavior.HoverUnderline;
(row.Cells[5] as DataGridViewLinkCell).TrackVisitedState = false;
}

private void saveButton_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -270,7 +276,7 @@ private void passwordsDataGrid_CellContentClick(object sender, DataGridViewCellE
if (e.RowIndex >= 0)
{
DataGridViewCell cell = passwordsDataGrid.Rows[e.RowIndex].Cells[e.ColumnIndex];
if (cell.ColumnIndex == 4)
if (cell.ColumnIndex == 5)
{
DeletedPassword(cell.RowIndex);
}
Expand Down Expand Up @@ -342,11 +348,12 @@ private void passwordsDataGrid_RowValidating(object sender, DataGridViewCellCanc
string program = (row.Cells[0].Value != null) ? row.Cells[0].Value.ToString():"";
string window = (row.Cells[1].Value != null) ? row.Cells[1].Value.ToString():"";
bool enter = (row.Cells[3].Value != null) ? (bool)row.Cells[3].Value : false;
bool clipboard = (row.Cells[4].Value != null) ? (bool)row.Cells[4].Value : false;
string password = row.Cells[2].Value.ToString();

if (isRowNew)
{
updatedPassword = Program.keyDatabase.AddOrUpdate(program, window, enter, password);
updatedPassword = Program.keyDatabase.AddOrUpdate(program, window, enter, clipboard, password);
}
else
{
Expand All @@ -366,7 +373,7 @@ private void passwordsDataGrid_RowValidating(object sender, DataGridViewCellCanc
return;
}

updatedPassword = Program.keyDatabase.UpdateIndex(row.Index, program, window, enter, password);
updatedPassword = Program.keyDatabase.UpdateIndex(row.Index, program, window, enter, clipboard, password);
}

updatePasswordCells(row, updatedPassword);
Expand Down
39 changes: 31 additions & 8 deletions fingerpass/KeyDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
Expand Down Expand Up @@ -135,6 +136,7 @@ public void Export(string path)
newDatabasePassword.Program = password.Program;
newDatabasePassword.Title = password.Title;
newDatabasePassword.PressEnter = password.PressEnter;
newDatabasePassword.UseClipboard = password.UseClipboard;
newDatabasePassword.PasswordHash = password.DecryptedPassword();
newDatabase.Passwords.Add(newDatabasePassword);
});
Expand Down Expand Up @@ -175,6 +177,7 @@ public void UpdatePassword(string newPassword, string currentPassword = null)
newDatabasePassword.Program = password.Program;
newDatabasePassword.Title = password.Title;
newDatabasePassword.PressEnter = password.PressEnter;
newDatabasePassword.UseClipboard = password.UseClipboard;
newDatabasePassword.PasswordHash = password.DecryptedPassword(); //temporarily store in clear text
newDatabase.Passwords.Add(newDatabasePassword);
});
Expand Down Expand Up @@ -389,8 +392,9 @@ public void RemoveIndex(int index)
/// <param name="programName">The program name that the password belongs to</param>
/// <param name="windowTitle">The window title that the password belongs to</param>
/// <param name="pressEnter">Whether or not to automatically press enter after the password is typed</param>
/// <param name="useClipboard">Whether or not to type this password using the clipboard via copy/paste</param>
/// <param name="clearPassword">The password in clear text, which will be encrypted. If left null, the password is not updated.</param>
public Password UpdateIndex(int index, string programName, string windowTitle, bool pressEnter, string clearPassword = null)
public Password UpdateIndex(int index, string programName, string windowTitle, bool pressEnter, bool useClipboard, string clearPassword = null)
{
int existingIndex = FindPasswordIndex(programName, windowTitle);
if (existingIndex >= 0 && existingIndex != index)
Expand All @@ -402,6 +406,7 @@ public Password UpdateIndex(int index, string programName, string windowTitle, b
database.Passwords[index].Program = programName;
database.Passwords[index].Title = windowTitle;
database.Passwords[index].PressEnter = pressEnter;
database.Passwords[index].UseClipboard = useClipboard;

if (clearPassword != null)
database.Passwords[index].PasswordHash = Protect(clearPassword);
Expand All @@ -422,10 +427,11 @@ public Password UpdateIndex(int index, string programName, string windowTitle, b
/// <param name="programName">The program name that the password belongs to</param>
/// <param name="windowTitle">The window title that the password belongs to</param>
/// <param name="pressEnter">Whether or not to automatically press enter after the password is typed</param>
/// <param name="useClipboard">Whether or not to type this password using the clipboard via copy/paste</param>
/// <param name="clearPassword">The password in clear text, which will be encrypted</param>
/// <param name="oldProgramName">If specified along with oldWindowTitle, this entry will be replaced with the new one</param>
/// <param name="oldWindowTitle">If specified along with oldProgramName, this entry will be replaced with the new one</param>
public Password AddOrUpdate(string programName, string windowTitle, bool pressEnter, string clearPassword, string oldProgramName = null, string oldWindowTitle = null)
public Password AddOrUpdate(string programName, string windowTitle, bool pressEnter, bool useClipboard, string clearPassword, string oldProgramName = null, string oldWindowTitle = null)
{
int index = -1;

Expand All @@ -446,6 +452,7 @@ public Password AddOrUpdate(string programName, string windowTitle, bool pressEn
database.Passwords[index].Program = programName;
database.Passwords[index].Title = windowTitle;
database.Passwords[index].PressEnter = pressEnter;
database.Passwords[index].UseClipboard = useClipboard;
database.Passwords[index].PasswordHash = Protect(clearPassword);

Save();
Expand All @@ -458,6 +465,7 @@ public Password AddOrUpdate(string programName, string windowTitle, bool pressEn
password.Program = programName;
password.Title = windowTitle;
password.PressEnter = pressEnter;
password.UseClipboard = useClipboard;
password.PasswordHash = Protect(clearPassword);
database.Passwords.Add(password);

Expand Down Expand Up @@ -661,6 +669,7 @@ public class Password
public string Title { get; set; }
public string PasswordHash { get; set; }
public bool PressEnter { get; set; } = true;
public bool UseClipboard { get; set; } = false;

/// <summary>
/// Returns the decrypted password in clear text
Expand All @@ -683,14 +692,28 @@ public string DecryptedPassword()
/// </summary>
public void Type()
{
//decrypt password and escape special characters that SendKeys uses...
string password = Regex.Replace(DecryptedPassword(), "[+^%~()]", "{$0}");
if (this.UseClipboard)
{
//clipboard access must be done on an STA thread...
Thread thread = new Thread(() =>
{
Clipboard.SetText(DecryptedPassword());
});
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread.Start();
thread.Join(); //Wait for the thread to end
}
else
{
//decrypt password and escape special characters that SendKeys uses...
string password = Regex.Replace(DecryptedPassword(), "[+^%~()]", "{$0}");

//maybe add an ENTER keypress...
if (this.PressEnter)
password += "{ENTER}";
//maybe add an ENTER keypress...
if (this.PressEnter)
password += "{ENTER}";

SendKeys.SendWait(password);
SendKeys.SendWait(password);
}
}
}
}
3 changes: 3 additions & 0 deletions fingerpass/MasterPasswordPromptForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ private void MasterPasswordPromptForm_Load(object sender, EventArgs e)

instructionsLabel.Text += "Please enter your master password to continue...";

this.ShowInTaskbar = true;
this.Activate();
this.BringToFront();
this.TopMost = true;
}

private void continueButton_Click(object sender, EventArgs e)
Expand Down
4 changes: 2 additions & 2 deletions fingerpass/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0")]
[assembly: AssemblyVersion("1.1.0")]
[assembly: AssemblyFileVersion("1.1.0")]
16 changes: 12 additions & 4 deletions fingerpass/TrayIcon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,21 @@ public void Show()
if (_isDisposed) throw new ObjectDisposedException("_notifyIcon");
_notifyIcon.Visible = true;

//on first run, add to startup...
//do some setup on the first run...
if (Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.FirstRun = false;
//try upgrading settings from a previous version...
Properties.Settings.Default.Upgrade();

//if still the first run, add to startup...
if (Properties.Settings.Default.FirstRun)
{
Properties.Settings.Default.FirstRun = false;
RegistryKey startupKeys = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
startupKeys.SetValue(Application.ProductName, Application.ExecutablePath);
}

Properties.Settings.Default.Save();
RegistryKey startupKeys = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
startupKeys.SetValue(Application.ProductName, Application.ExecutablePath);
}

//if salts haven't been set yet, set them...
Expand Down
4 changes: 2 additions & 2 deletions service/fingerpass_service/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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.1.0.0")]
[assembly: AssemblyFileVersion("1.1.0.0")]

0 comments on commit f8ca6e8

Please sign in to comment.