Deleted everything profile related and started semi-fresh
This commit is contained in:
75
Password Manager/ConfigFileManager.cs
Normal file
75
Password Manager/ConfigFileManager.cs
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
using Microsoft.VisualBasic.FileIO;
|
||||||
|
|
||||||
|
namespace Password_Manager
|
||||||
|
{
|
||||||
|
static class ConfigFileManager
|
||||||
|
{
|
||||||
|
private static string configPath = SpecialDirectories.CurrentUserApplicationData + "\\config.cfg";
|
||||||
|
|
||||||
|
#region Config flags
|
||||||
|
/*Configuration: (format: fieldname=value)
|
||||||
|
|
||||||
|
pwdStorePath: path to the folder which contains the .gpg files
|
||||||
|
recipient: whose public key to use for encryption when a new password is created
|
||||||
|
*/
|
||||||
|
private const char DELIMETER = '=';
|
||||||
|
private const string RECIPIENT = "recipient";
|
||||||
|
private const string PATH = "pwdStorePath";
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
public static string GetPath()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StreamReader sr = new StreamReader(configPath);
|
||||||
|
if (sr != null)
|
||||||
|
{
|
||||||
|
while (!sr.EndOfStream)
|
||||||
|
{
|
||||||
|
string[]? fields = sr.ReadLine().Split(DELIMETER);
|
||||||
|
if (fields != null)
|
||||||
|
{
|
||||||
|
if (fields[0] == PATH)
|
||||||
|
{
|
||||||
|
return fields[1];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new FileNotFoundException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (FileNotFoundException)
|
||||||
|
{
|
||||||
|
CreateDefaultConfig();
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return @"C:\Users\Typo\pass"; //TODO: temporary default value
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CreateDefaultConfig()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
StreamWriter sw = new StreamWriter(configPath);
|
||||||
|
sw.WriteLine(RECIPIENT + DELIMETER + "typo");
|
||||||
|
sw.WriteLine(PATH + DELIMETER + @"C:\Users\Typo\pass");
|
||||||
|
sw.Close();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -34,10 +34,6 @@ namespace Password_Manager
|
|||||||
{
|
{
|
||||||
MessageBox.Show("Please enter a valid number for the password's length.", "Error: Invalid field", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show("Please enter a valid number for the password's length.", "Error: Invalid field", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
catch (ArgumentNullException error)
|
|
||||||
{
|
|
||||||
MessageBox.Show(error.ToString(), "Error: No profile path", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
catch (IOException error)
|
catch (IOException error)
|
||||||
{
|
{
|
||||||
MessageBox.Show(error.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(error.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
|
|||||||
54
Password Manager/MainForm.Designer.cs
generated
54
Password Manager/MainForm.Designer.cs
generated
@@ -1,6 +1,6 @@
|
|||||||
namespace Password_Manager
|
namespace Password_Manager
|
||||||
{
|
{
|
||||||
sealed partial class MainForm : PasswordManagerForm
|
sealed partial class MainForm : Form
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Required designer variable.
|
/// Required designer variable.
|
||||||
@@ -30,9 +30,6 @@
|
|||||||
{
|
{
|
||||||
SearchBox = new TextBox();
|
SearchBox = new TextBox();
|
||||||
ResultList = new PasswordListBox();
|
ResultList = new PasswordListBox();
|
||||||
ProfileSelection = new ComboBox();
|
|
||||||
AddProfile = new Button();
|
|
||||||
DeleteProfile = new Button();
|
|
||||||
GeneratePassword = new Button();
|
GeneratePassword = new Button();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@@ -55,43 +52,6 @@
|
|||||||
ResultList.Name = "resultList";
|
ResultList.Name = "resultList";
|
||||||
ResultList.Size = new Size(225, 274);
|
ResultList.Size = new Size(225, 274);
|
||||||
ResultList.TabIndex = 1;
|
ResultList.TabIndex = 1;
|
||||||
ResultList.CurrentProfilePathRequest += () => CurrentProfilePathRequest();
|
|
||||||
ResultList.SearchQueryRequest += () => SearchBox.Text;
|
|
||||||
//
|
|
||||||
// profileSelection
|
|
||||||
//
|
|
||||||
ProfileSelection.DisplayMember = "Name";
|
|
||||||
ProfileSelection.DropDownHeight = 100;
|
|
||||||
ProfileSelection.DropDownWidth = 176;
|
|
||||||
ProfileSelection.FormattingEnabled = true;
|
|
||||||
ProfileSelection.IntegralHeight = false;
|
|
||||||
ProfileSelection.Location = new Point(513, 20);
|
|
||||||
ProfileSelection.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
ProfileSelection.Name = "profileSelection";
|
|
||||||
ProfileSelection.Size = new Size(176, 23);
|
|
||||||
ProfileSelection.TabIndex = 2;
|
|
||||||
ProfileSelection.SelectionChangeCommitted += ChangeProfile;
|
|
||||||
//
|
|
||||||
// addProfile
|
|
||||||
//
|
|
||||||
AddProfile.Location = new Point(513, 45);
|
|
||||||
AddProfile.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
AddProfile.Name = "addProfile";
|
|
||||||
AddProfile.Size = new Size(83, 22);
|
|
||||||
AddProfile.TabIndex = 3;
|
|
||||||
AddProfile.Text = "Add";
|
|
||||||
AddProfile.UseVisualStyleBackColor = true;
|
|
||||||
AddProfile.Click += OpenProfileCreator;
|
|
||||||
//
|
|
||||||
// removeProfile
|
|
||||||
//
|
|
||||||
DeleteProfile.Location = new Point(605, 45);
|
|
||||||
DeleteProfile.Margin = new Padding(3, 2, 3, 2);
|
|
||||||
DeleteProfile.Name = "removeProfile";
|
|
||||||
DeleteProfile.Size = new Size(83, 22);
|
|
||||||
DeleteProfile.TabIndex = 4;
|
|
||||||
DeleteProfile.Text = "Delete";
|
|
||||||
DeleteProfile.UseVisualStyleBackColor = true;
|
|
||||||
//
|
//
|
||||||
// button1
|
// button1
|
||||||
//
|
//
|
||||||
@@ -109,9 +69,6 @@
|
|||||||
AutoScaleMode = AutoScaleMode.Font;
|
AutoScaleMode = AutoScaleMode.Font;
|
||||||
ClientSize = new Size(700, 338);
|
ClientSize = new Size(700, 338);
|
||||||
Controls.Add(GeneratePassword);
|
Controls.Add(GeneratePassword);
|
||||||
Controls.Add(DeleteProfile);
|
|
||||||
Controls.Add(AddProfile);
|
|
||||||
Controls.Add(ProfileSelection);
|
|
||||||
Controls.Add(ResultList);
|
Controls.Add(ResultList);
|
||||||
Controls.Add(SearchBox);
|
Controls.Add(SearchBox);
|
||||||
Margin = new Padding(3, 2, 3, 2);
|
Margin = new Padding(3, 2, 3, 2);
|
||||||
@@ -123,11 +80,8 @@
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
protected override TextBox SearchBox { get; set; }
|
private TextBox SearchBox;
|
||||||
protected override PasswordListBox ResultList { get; set; }
|
private PasswordListBox ResultList;
|
||||||
protected override ComboBox ProfileSelection { get; set; }
|
private Button GeneratePassword;
|
||||||
protected override Button AddProfile { get; set; }
|
|
||||||
protected override Button DeleteProfile { get; set; }
|
|
||||||
protected override Button GeneratePassword { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
|
|
||||||
namespace Password_Manager
|
|
||||||
{
|
|
||||||
public sealed partial class MainForm : PasswordManagerForm
|
|
||||||
{
|
|
||||||
public override event ProfileDataRequest CurrentProfilePathRequest;
|
|
||||||
public override event ProfileDataRequest CurrentProfileNameRequest;
|
|
||||||
public override event ProfileList CurrentProfileListRequest;
|
|
||||||
public override event ProfileChange CurrentProfileChanged;
|
|
||||||
public override event Save SaveRequest;
|
|
||||||
public override event NewProfile NewProfileRequest;
|
|
||||||
|
|
||||||
public MainForm(
|
|
||||||
ProfileDataRequest CurrentProfileNameRequest,
|
|
||||||
ProfileDataRequest CurrentProfilePathRequest,
|
|
||||||
ProfileList CurrentProfileListRequest,
|
|
||||||
ProfileChange CurrentProfileChanged,
|
|
||||||
Save SaveRequest,
|
|
||||||
NewProfile NewProfileRequest)
|
|
||||||
{
|
|
||||||
this.CurrentProfileNameRequest = CurrentProfileNameRequest;
|
|
||||||
this.CurrentProfilePathRequest = CurrentProfilePathRequest;
|
|
||||||
this.CurrentProfileListRequest = CurrentProfileListRequest;
|
|
||||||
this.CurrentProfileChanged = CurrentProfileChanged;
|
|
||||||
this.SaveRequest = SaveRequest;
|
|
||||||
this.NewProfileRequest = NewProfileRequest;
|
|
||||||
|
|
||||||
InitializeComponent();
|
|
||||||
RefreshCurrentProfile();
|
|
||||||
SaveRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,51 +1,22 @@
|
|||||||
using System.ComponentModel.Design;
|
|
||||||
|
|
||||||
namespace Password_Manager
|
namespace Password_Manager
|
||||||
{
|
{
|
||||||
sealed public partial class MainForm : PasswordManagerForm
|
sealed public partial class MainForm : Form
|
||||||
{
|
{
|
||||||
private void OpenProfileCreator(object sender, EventArgs e)
|
public event DataRequest PathRequest;
|
||||||
|
|
||||||
|
public MainForm(DataRequest PathRequest)
|
||||||
{
|
{
|
||||||
NewProfileForm npf = new NewProfileForm();
|
this.PathRequest = PathRequest;
|
||||||
npf.ReloadMainFormRequest += () => RefreshCurrentProfile();
|
InitializeComponent();
|
||||||
npf.SaveRequest += this.SaveRequest;
|
|
||||||
npf.NewProfileRequest += this.NewProfileRequest;
|
ResultList = new PasswordListBox(PathRequest);
|
||||||
npf.ShowDialog();
|
ResultList.ReloadResults();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OpenPasswordGenerator(object sender, EventArgs e)
|
private void OpenPasswordGenerator(object sender, EventArgs e)
|
||||||
{
|
{
|
||||||
string? tmp = CurrentProfilePathRequest();
|
GeneratePassword gp = new GeneratePassword(SearchBox.Text, PathRequest());
|
||||||
if (tmp != null)
|
|
||||||
{
|
|
||||||
GeneratePassword gp = new GeneratePassword(SearchBox.Text, tmp);
|
|
||||||
gp.ShowDialog();
|
gp.ShowDialog();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("No path specified", "Event error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void ChangeProfile(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
CurrentProfileChanged(ProfileSelection.Text);
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void RefreshCurrentProfile()
|
|
||||||
{
|
|
||||||
ProfileSelection.SelectedIndex = -1;
|
|
||||||
string[] items = CurrentProfileListRequest();
|
|
||||||
for (int i = 0; i < items.Length; i++)
|
|
||||||
{
|
|
||||||
ProfileSelection.Items.Add(items[i]);
|
|
||||||
if (items[i] == CurrentProfileNameRequest())
|
|
||||||
{
|
|
||||||
ProfileSelection.SelectedIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.Text = CurrentProfileNameRequest();
|
|
||||||
ResultList.ReloadResults();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
108
Password Manager/NewProfileForm.Designer.cs
generated
108
Password Manager/NewProfileForm.Designer.cs
generated
@@ -1,108 +0,0 @@
|
|||||||
namespace Password_Manager
|
|
||||||
{
|
|
||||||
partial class NewProfileForm
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Required designer variable.
|
|
||||||
/// </summary>
|
|
||||||
private System.ComponentModel.IContainer components = null;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Clean up any resources being used.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
|
||||||
protected override void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (disposing && (components != null))
|
|
||||||
{
|
|
||||||
components.Dispose();
|
|
||||||
}
|
|
||||||
base.Dispose(disposing);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Windows Form Designer generated code
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Required method for Designer support - do not modify
|
|
||||||
/// the contents of this method with the code editor.
|
|
||||||
/// </summary>
|
|
||||||
private void InitializeComponent()
|
|
||||||
{
|
|
||||||
button1 = new Button();
|
|
||||||
button2 = new Button();
|
|
||||||
button3 = new Button();
|
|
||||||
nameTextBox = new TextBox();
|
|
||||||
pathTextBox = new TextBox();
|
|
||||||
SuspendLayout();
|
|
||||||
//
|
|
||||||
// button1
|
|
||||||
//
|
|
||||||
button1.Location = new Point(212, 45);
|
|
||||||
button1.Name = "button1";
|
|
||||||
button1.Size = new Size(94, 29);
|
|
||||||
button1.TabIndex = 0;
|
|
||||||
button1.Text = "Browse";
|
|
||||||
button1.UseVisualStyleBackColor = true;
|
|
||||||
button1.Click += ChooseFolder;
|
|
||||||
//
|
|
||||||
// button2
|
|
||||||
//
|
|
||||||
button2.Location = new Point(161, 78);
|
|
||||||
button2.Name = "button2";
|
|
||||||
button2.Size = new Size(145, 29);
|
|
||||||
button2.TabIndex = 1;
|
|
||||||
button2.Text = "Save";
|
|
||||||
button2.UseVisualStyleBackColor = true;
|
|
||||||
button2.Click += Save;
|
|
||||||
//
|
|
||||||
// button3
|
|
||||||
//
|
|
||||||
button3.Location = new Point(12, 78);
|
|
||||||
button3.Name = "button3";
|
|
||||||
button3.Size = new Size(145, 29);
|
|
||||||
button3.TabIndex = 2;
|
|
||||||
button3.Text = "Cancel";
|
|
||||||
button3.UseVisualStyleBackColor = true;
|
|
||||||
button3.Click += Cancel;
|
|
||||||
//
|
|
||||||
// nameTextBox
|
|
||||||
//
|
|
||||||
nameTextBox.Location = new Point(12, 12);
|
|
||||||
nameTextBox.Name = "nameTextBox";
|
|
||||||
nameTextBox.PlaceholderText = "Work";
|
|
||||||
nameTextBox.Size = new Size(194, 27);
|
|
||||||
nameTextBox.TabIndex = 3;
|
|
||||||
//
|
|
||||||
// pathTextBox
|
|
||||||
//
|
|
||||||
pathTextBox.Location = new Point(12, 45);
|
|
||||||
pathTextBox.Name = "pathTextBox";
|
|
||||||
pathTextBox.PlaceholderText = "C:\\Passwords";
|
|
||||||
pathTextBox.Size = new Size(194, 27);
|
|
||||||
pathTextBox.TabIndex = 4;
|
|
||||||
//
|
|
||||||
// NewProfileForm
|
|
||||||
//
|
|
||||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
|
||||||
AutoScaleMode = AutoScaleMode.Font;
|
|
||||||
ClientSize = new Size(317, 127);
|
|
||||||
Controls.Add(pathTextBox);
|
|
||||||
Controls.Add(nameTextBox);
|
|
||||||
Controls.Add(button3);
|
|
||||||
Controls.Add(button2);
|
|
||||||
Controls.Add(button1);
|
|
||||||
Name = "NewProfileForm";
|
|
||||||
Text = "Create profile";
|
|
||||||
ResumeLayout(false);
|
|
||||||
PerformLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private Button button1;
|
|
||||||
private Button button2;
|
|
||||||
private Button button3;
|
|
||||||
private TextBox nameTextBox;
|
|
||||||
private TextBox pathTextBox;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,45 +0,0 @@
|
|||||||
namespace Password_Manager
|
|
||||||
{
|
|
||||||
public delegate void ReloadPasswords();
|
|
||||||
public partial class NewProfileForm : Form
|
|
||||||
{
|
|
||||||
public event NewProfile? NewProfileRequest;
|
|
||||||
public event ReloadPasswords? ReloadMainFormRequest;
|
|
||||||
public event Save? SaveRequest;
|
|
||||||
|
|
||||||
public NewProfileForm()
|
|
||||||
{
|
|
||||||
InitializeComponent();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void ChooseFolder(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
FolderBrowserDialog dialog = new FolderBrowserDialog();
|
|
||||||
if (dialog.ShowDialog() == DialogResult.OK)
|
|
||||||
{
|
|
||||||
pathTextBox.Text = dialog.SelectedPath;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Save(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
if (nameTextBox.Text != "" && pathTextBox.Text != "")
|
|
||||||
{
|
|
||||||
NewProfileRequest?.Invoke(nameTextBox.Text, pathTextBox.Text);
|
|
||||||
ReloadMainFormRequest?.Invoke();
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
|
|
||||||
SaveRequest?.Invoke();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void Cancel(object sender, EventArgs e)
|
|
||||||
{
|
|
||||||
this.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,60 +0,0 @@
|
|||||||
<root>
|
|
||||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
|
||||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
|
||||||
<xsd:element name="root" msdata:IsDataSet="true">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:choice maxOccurs="unbounded">
|
|
||||||
<xsd:element name="metadata">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="assembly">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:attribute name="alias" type="xsd:string" />
|
|
||||||
<xsd:attribute name="name" type="xsd:string" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="data">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
|
||||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
|
||||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
|
||||||
<xsd:attribute ref="xml:space" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
<xsd:element name="resheader">
|
|
||||||
<xsd:complexType>
|
|
||||||
<xsd:sequence>
|
|
||||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
|
||||||
</xsd:sequence>
|
|
||||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:choice>
|
|
||||||
</xsd:complexType>
|
|
||||||
</xsd:element>
|
|
||||||
</xsd:schema>
|
|
||||||
<resheader name="resmimetype">
|
|
||||||
<value>text/microsoft-resx</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="version">
|
|
||||||
<value>2.0</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="reader">
|
|
||||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
<resheader name="writer">
|
|
||||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
|
||||||
</resheader>
|
|
||||||
</root>
|
|
||||||
@@ -7,17 +7,8 @@
|
|||||||
<Compile Update="MainForm.cs">
|
<Compile Update="MainForm.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Update="MainForm.Events.cs">
|
|
||||||
<SubType>Form</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Update="NewProfileForm.cs">
|
|
||||||
<SubType>Form</SubType>
|
|
||||||
</Compile>
|
|
||||||
<Compile Update="PasswordListBox.cs">
|
<Compile Update="PasswordListBox.cs">
|
||||||
<SubType>Component</SubType>
|
<SubType>Component</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Update="PasswordManagerForm.cs">
|
|
||||||
<SubType>Form</SubType>
|
|
||||||
</Compile>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@@ -1,24 +1,42 @@
|
|||||||
namespace Password_Manager
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
namespace Password_Manager
|
||||||
{
|
{
|
||||||
public delegate string SearchQuery();
|
public delegate string SearchQuery();
|
||||||
public class PasswordListBox : ListBox
|
public class PasswordListBox : ListBox
|
||||||
{
|
{
|
||||||
public event ProfileDataRequest? CurrentProfilePathRequest;
|
public event DataRequest? PathRequest;
|
||||||
public event SearchQuery? SearchQueryRequest;
|
public event SearchQuery? SearchQueryRequest;
|
||||||
|
|
||||||
public PasswordListBox() : base() { }
|
public PasswordListBox(DataRequest PathRequest, SearchQuery? SearchQueryRequest = null) : base()
|
||||||
|
{
|
||||||
|
this.PathRequest = PathRequest;
|
||||||
|
this.SearchQueryRequest = SearchQueryRequest;
|
||||||
|
}
|
||||||
|
|
||||||
public void ReloadResults(object sender = null, EventArgs arg = null)
|
public PasswordListBox() : base() { }
|
||||||
|
/*do not instantiate this class using this constructor if you want to use the ReloadResults method afterwards.
|
||||||
|
Use this so that the MainForm.Designer.cs file doesn't have a stroke due to Event References, then re-instantiate the object
|
||||||
|
afterwards using the other constructor*/
|
||||||
|
|
||||||
|
public void ReloadResults(object? sender = null, EventArgs? arg = null)
|
||||||
{
|
{
|
||||||
DirectoryInfo d;
|
DirectoryInfo d;
|
||||||
FileInfo[] files = new FileInfo[0];
|
FileInfo[] files = new FileInfo[0];
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
d = new DirectoryInfo(CurrentProfilePathRequest?.Invoke());
|
if (PathRequest != null)
|
||||||
|
{
|
||||||
|
d = new DirectoryInfo(PathRequest());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw new InvalidOperationException("You cannot use this method if you instantiated the object using the parameterless constructor");
|
||||||
|
}
|
||||||
files = d.GetFiles("*.gpg");
|
files = d.GetFiles("*.gpg");
|
||||||
} catch (ArgumentNullException e)
|
} catch (ArgumentNullException e)
|
||||||
{
|
{
|
||||||
MessageBox.Show(e.ToString(), "Error: Invalid profile path", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
MessageBox.Show(e.ToString(), "Error: Invalid path", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||||
}
|
}
|
||||||
|
|
||||||
string[] arrayTmp = new string[files.Length];
|
string[] arrayTmp = new string[files.Length];
|
||||||
@@ -29,8 +47,8 @@
|
|||||||
List<string> elements = new List<string>(arrayTmp);
|
List<string> elements = new List<string>(arrayTmp);
|
||||||
|
|
||||||
string[] copy = elements.ToArray();
|
string[] copy = elements.ToArray();
|
||||||
string searchQuery = SearchQueryRequest?.Invoke();
|
string? searchQuery = SearchQueryRequest?.Invoke();
|
||||||
if (searchQuery != "") //we have a search query
|
if (searchQuery != null) //we have a search query
|
||||||
{
|
{
|
||||||
foreach (string s in copy)
|
foreach (string s in copy)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,28 +0,0 @@
|
|||||||
namespace Password_Manager
|
|
||||||
{
|
|
||||||
public delegate void ProfileChange(string profileName); //Fires when we want to change the CurrentProfile field of ProfileHandler based on the combobox selection
|
|
||||||
public delegate string[] ProfileList(); //Fires when we need a list of Profile names, like for the combobox items
|
|
||||||
public delegate void Save(); //Fire whenever we want to save the current state of profiles
|
|
||||||
public delegate void NewProfile(string profileName, string profilePath); //Fires whenever a NewProfileForm has requested the creation of a new profile. This just forwards that request to ProfileHandler
|
|
||||||
|
|
||||||
public abstract class PasswordManagerForm : Form
|
|
||||||
{
|
|
||||||
protected abstract ComboBox ProfileSelection { get; set; }
|
|
||||||
protected abstract PasswordListBox ResultList { get; set; }
|
|
||||||
protected abstract TextBox SearchBox { get; set; }
|
|
||||||
protected abstract Button AddProfile { get; set; }
|
|
||||||
protected abstract Button DeleteProfile { get; set; }
|
|
||||||
protected abstract Button GeneratePassword { get; set; }
|
|
||||||
|
|
||||||
public abstract event ProfileDataRequest CurrentProfilePathRequest;
|
|
||||||
public abstract event ProfileDataRequest CurrentProfileNameRequest;
|
|
||||||
public abstract event ProfileList CurrentProfileListRequest;
|
|
||||||
public abstract event ProfileChange CurrentProfileChanged;
|
|
||||||
public abstract event Save SaveRequest;
|
|
||||||
public abstract event NewProfile NewProfileRequest;
|
|
||||||
|
|
||||||
|
|
||||||
protected abstract void ChangeProfile(object sender, EventArgs e);
|
|
||||||
public abstract void RefreshCurrentProfile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,48 +0,0 @@
|
|||||||
using System.Collections;
|
|
||||||
|
|
||||||
namespace Profiles
|
|
||||||
{
|
|
||||||
abstract class IList<T> : IEnumerable<T>
|
|
||||||
{
|
|
||||||
protected T[] list;
|
|
||||||
|
|
||||||
public int Length
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return list.Length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public T this[int index]
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
return list[index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public IList()
|
|
||||||
{
|
|
||||||
this.list = new T[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void Add(T item);
|
|
||||||
public abstract void Remove(T item);
|
|
||||||
public abstract T SearchByName(string name);
|
|
||||||
public void Clear()
|
|
||||||
{
|
|
||||||
list = new T[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerator<T> GetEnumerator()
|
|
||||||
{
|
|
||||||
return ((IEnumerable<T>)list).GetEnumerator();
|
|
||||||
}
|
|
||||||
|
|
||||||
IEnumerator IEnumerable.GetEnumerator()
|
|
||||||
{
|
|
||||||
return list.GetEnumerator();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,16 +0,0 @@
|
|||||||
namespace Profiles
|
|
||||||
{
|
|
||||||
public sealed class Profile
|
|
||||||
{
|
|
||||||
public string Name { get; } //the name of the password store profile ("personal", "work", or similar)
|
|
||||||
public string Path { get; } //path of the folder containing the password store
|
|
||||||
//public event PasswordStoreChange Change; //runs if a new password is added, or if one is removed
|
|
||||||
|
|
||||||
public Profile(string name, string path)
|
|
||||||
{
|
|
||||||
Name = name;
|
|
||||||
Path = path;
|
|
||||||
//Change = change;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,142 +0,0 @@
|
|||||||
using Password_Manager;
|
|
||||||
using Microsoft.VisualBasic.FileIO;
|
|
||||||
|
|
||||||
namespace Profiles
|
|
||||||
{
|
|
||||||
static class ProfileHandler
|
|
||||||
{
|
|
||||||
public static Profile CurrentProfile;
|
|
||||||
public static ProfileList ListOfProfiles;
|
|
||||||
private static string filePath = SpecialDirectories.CurrentUserApplicationData + "\\Profiles.csv";
|
|
||||||
|
|
||||||
public static void AddProfile(string profileName, string profilePath)
|
|
||||||
{
|
|
||||||
ListOfProfiles.Add(new Profile(profileName, profilePath));
|
|
||||||
ChangeProfiles(profileName);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ChangeProfiles(string profileName)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
CurrentProfile = ListOfProfiles.SearchByName(profileName);
|
|
||||||
} catch (ProfileNotFoundException)
|
|
||||||
{
|
|
||||||
MessageBox.Show("The selected profile cannot be found", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void Init()
|
|
||||||
{
|
|
||||||
ListOfProfiles = new ProfileList();
|
|
||||||
|
|
||||||
if (File.Exists(filePath))
|
|
||||||
{
|
|
||||||
LoadProfilesFile();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateProfilesFile();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static void LoadProfilesFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StreamReader sr = new StreamReader(filePath);
|
|
||||||
string[] lines = sr.ReadToEnd().Split("\n");
|
|
||||||
foreach (string line in lines)
|
|
||||||
{
|
|
||||||
string[] fields = line.Split(',');
|
|
||||||
try
|
|
||||||
{
|
|
||||||
ListOfProfiles.Add(new Profile(fields[0], fields[1]));
|
|
||||||
} catch (IndexOutOfRangeException)
|
|
||||||
{
|
|
||||||
//File is messed up, creating new one
|
|
||||||
sr.Close();
|
|
||||||
CreateProfilesFile();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sr.Close();
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void TrimLastLine()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StreamReader sr = new StreamReader(filePath);
|
|
||||||
List<string> validLines = new List<string>();
|
|
||||||
|
|
||||||
while (!sr.EndOfStream)
|
|
||||||
{
|
|
||||||
string? line = sr.ReadLine();
|
|
||||||
if (line != null)
|
|
||||||
{
|
|
||||||
validLines.Add(line);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sr.Close();
|
|
||||||
File.WriteAllLines(filePath, validLines);
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
} catch (UnauthorizedAccessException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SaveProfiles()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StreamWriter sw = new StreamWriter(filePath);
|
|
||||||
|
|
||||||
foreach (Profile p in ListOfProfiles)
|
|
||||||
{
|
|
||||||
sw.WriteLine($"{p.Name},{p.Path}");
|
|
||||||
}
|
|
||||||
|
|
||||||
sw.Close();
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
} catch (UnauthorizedAccessException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "Can't access profiles file", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void CreateProfilesFile()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
StreamWriter sw = new StreamWriter(filePath);
|
|
||||||
|
|
||||||
string[] parameters = new string[2];
|
|
||||||
|
|
||||||
NewProfileForm np = new NewProfileForm();
|
|
||||||
np.NewProfileRequest += (string profileName, string profilePath) =>
|
|
||||||
{
|
|
||||||
Profile firstProfile = new Profile(profileName, profilePath);
|
|
||||||
ListOfProfiles.Add(firstProfile);
|
|
||||||
ChangeProfiles(firstProfile.Name);
|
|
||||||
sw.WriteLine($"{firstProfile.Name},{firstProfile.Path}");
|
|
||||||
sw.Close();
|
|
||||||
TrimLastLine();
|
|
||||||
};
|
|
||||||
np.ShowDialog();
|
|
||||||
} catch (IOException e)
|
|
||||||
{
|
|
||||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,71 +0,0 @@
|
|||||||
namespace Profiles
|
|
||||||
{
|
|
||||||
sealed class ProfileList : IList<Profile>
|
|
||||||
{
|
|
||||||
public ProfileList() : base() { }
|
|
||||||
|
|
||||||
public override void Add(Profile p)
|
|
||||||
{
|
|
||||||
//grow the list by 1 and copy all existing items
|
|
||||||
Profile[] tmp = new Profile[this.Length + 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < this.Length; i++)
|
|
||||||
{
|
|
||||||
tmp[i] = this[i];
|
|
||||||
}
|
|
||||||
|
|
||||||
this.list = tmp;
|
|
||||||
|
|
||||||
//--------------------------------------------------------
|
|
||||||
|
|
||||||
list[this.Length - 1] = p;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void Remove(Profile p)
|
|
||||||
{
|
|
||||||
Profile[] tmp = new Profile[this.Length - 1];
|
|
||||||
|
|
||||||
for (int i = 0; i < tmp.Length; i++)
|
|
||||||
{
|
|
||||||
if (this[i] != p)
|
|
||||||
{
|
|
||||||
tmp[i] = this[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
this.list = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override Profile SearchByName(string name)
|
|
||||||
{
|
|
||||||
Profile? result = null;
|
|
||||||
|
|
||||||
for (int i = 0; i < this.Length; i++)
|
|
||||||
{
|
|
||||||
if (this[i].Name == name)
|
|
||||||
{
|
|
||||||
result = this[i];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (result == null)
|
|
||||||
{
|
|
||||||
throw new ProfileNotFoundException();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public string[] GetNameList()
|
|
||||||
{
|
|
||||||
string[] array = new string[this.Length];
|
|
||||||
for (int i = 0; i < this.Length; i++)
|
|
||||||
{
|
|
||||||
array[i] = this[i].Name;
|
|
||||||
}
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
namespace Profiles
|
|
||||||
{
|
|
||||||
sealed class ProfileNotFoundException : Exception
|
|
||||||
{
|
|
||||||
public ProfileNotFoundException() : base() { }
|
|
||||||
public ProfileNotFoundException(string message) : base(message) { }
|
|
||||||
public ProfileNotFoundException(string message, Exception inner) : base(message, inner) { }
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
using Profiles;
|
|
||||||
|
|
||||||
namespace Password_Manager
|
namespace Password_Manager
|
||||||
{
|
{
|
||||||
public delegate string ProfileDataRequest(); //Fire whenever a specific field of ProfileHandler.CurrentProfile is needed
|
public delegate string DataRequest(); //Fire whenever a specific field of ProfileHandler.CurrentProfile is needed
|
||||||
internal static class Program
|
internal static class Program
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -12,17 +10,11 @@ namespace Password_Manager
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
ApplicationConfiguration.Initialize();
|
ApplicationConfiguration.Initialize();
|
||||||
ProfileHandler.Init();
|
|
||||||
Application.Run(mainForm);
|
Application.Run(mainForm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MainForm mainForm = new MainForm(
|
public static MainForm mainForm = new MainForm(
|
||||||
() => ProfileHandler.CurrentProfile.Name,
|
() => ConfigFileManager.GetPath()
|
||||||
() => ProfileHandler.CurrentProfile.Path,
|
|
||||||
() => ProfileHandler.ListOfProfiles.GetNameList(),
|
|
||||||
(profileName) => ProfileHandler.ChangeProfiles(profileName),
|
|
||||||
() => ProfileHandler.SaveProfiles(),
|
|
||||||
(profileName, profilePath) => ProfileHandler.AddProfile(profileName, profilePath)
|
|
||||||
); //needed at creation so that MainForm may pass this method down to other classes in its constructor
|
); //needed at creation so that MainForm may pass this method down to other classes in its constructor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user