kill me
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
135
Password Manager/GeneratePassword.Designer.cs
generated
Normal file
135
Password Manager/GeneratePassword.Designer.cs
generated
Normal file
@@ -0,0 +1,135 @@
|
||||
namespace Password_Manager
|
||||
{
|
||||
partial class GeneratePassword
|
||||
{
|
||||
/// <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()
|
||||
{
|
||||
passwordName = new TextBox();
|
||||
label1 = new Label();
|
||||
label2 = new Label();
|
||||
passwordLength = new TextBox();
|
||||
noSymbols = new CheckBox();
|
||||
generate = new Button();
|
||||
cancel = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// textBox1
|
||||
//
|
||||
passwordName.Location = new Point(12, 33);
|
||||
passwordName.Name = "textBox1";
|
||||
passwordName.PlaceholderText = "website.com";
|
||||
passwordName.Size = new Size(156, 23);
|
||||
passwordName.TabIndex = 0;
|
||||
//
|
||||
// label1
|
||||
//
|
||||
label1.AutoSize = true;
|
||||
label1.Location = new Point(12, 15);
|
||||
label1.Name = "label1";
|
||||
label1.Size = new Size(39, 15);
|
||||
label1.TabIndex = 1;
|
||||
label1.Text = "Name";
|
||||
//
|
||||
// label2
|
||||
//
|
||||
label2.AutoSize = true;
|
||||
label2.Location = new Point(12, 59);
|
||||
label2.Name = "label2";
|
||||
label2.Size = new Size(44, 15);
|
||||
label2.TabIndex = 2;
|
||||
label2.Text = "Length";
|
||||
//
|
||||
// textBox2
|
||||
//
|
||||
passwordLength.Location = new Point(12, 77);
|
||||
passwordLength.Name = "textBox2";
|
||||
passwordLength.PlaceholderText = "16";
|
||||
passwordLength.Size = new Size(156, 23);
|
||||
passwordLength.TabIndex = 3;
|
||||
//
|
||||
// checkBox1
|
||||
//
|
||||
noSymbols.AutoSize = true;
|
||||
noSymbols.Location = new Point(12, 106);
|
||||
noSymbols.Name = "checkBox1";
|
||||
noSymbols.Size = new Size(89, 19);
|
||||
noSymbols.TabIndex = 4;
|
||||
noSymbols.Text = "No symbols";
|
||||
noSymbols.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
generate.Location = new Point(93, 131);
|
||||
generate.Name = "button1";
|
||||
generate.Size = new Size(75, 23);
|
||||
generate.TabIndex = 5;
|
||||
generate.Text = "Generate";
|
||||
generate.UseVisualStyleBackColor = true;
|
||||
generate.Click += Generate;
|
||||
//
|
||||
// button2
|
||||
//
|
||||
cancel.Location = new Point(12, 131);
|
||||
cancel.Name = "button2";
|
||||
cancel.Size = new Size(75, 23);
|
||||
cancel.TabIndex = 6;
|
||||
cancel.Text = "Cancel";
|
||||
cancel.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// GeneratePassword
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(187, 173);
|
||||
Controls.Add(cancel);
|
||||
Controls.Add(generate);
|
||||
Controls.Add(noSymbols);
|
||||
Controls.Add(passwordLength);
|
||||
Controls.Add(label2);
|
||||
Controls.Add(label1);
|
||||
Controls.Add(passwordName);
|
||||
Name = "GeneratePassword";
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
private void Generate_Click(object sender, EventArgs e)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private TextBox passwordName;
|
||||
private Label label1;
|
||||
private Label label2;
|
||||
private TextBox passwordLength;
|
||||
private CheckBox noSymbols;
|
||||
private Button generate;
|
||||
private Button cancel;
|
||||
}
|
||||
}
|
||||
48
Password Manager/GeneratePassword.cs
Normal file
48
Password Manager/GeneratePassword.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using Password_Generator;
|
||||
|
||||
namespace Password_Manager
|
||||
{
|
||||
public partial class GeneratePassword : Form
|
||||
{
|
||||
private string currentPath;
|
||||
|
||||
public GeneratePassword(string name, string currentPath)
|
||||
{
|
||||
InitializeComponent();
|
||||
passwordName.Text = name;
|
||||
this.currentPath = currentPath;
|
||||
}
|
||||
|
||||
public void Generate(object sender, EventArgs e)
|
||||
{
|
||||
if (passwordName.Text == "" && passwordLength.Text == "")
|
||||
{
|
||||
MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
bool valid = false;
|
||||
while (!valid)
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(currentPath + $"{passwordName.Text}.txt"); //TODO: rename to .gpg when encryption is possible
|
||||
valid = true;
|
||||
sw.Write(Generator.New(Convert.ToInt32(passwordLength.Text), noSymbols.Checked));
|
||||
sw.Close();
|
||||
}
|
||||
catch (FormatException)
|
||||
{
|
||||
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)
|
||||
{
|
||||
MessageBox.Show(error.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
60
Password Manager/GeneratePassword.resx
Normal file
60
Password Manager/GeneratePassword.resx
Normal file
@@ -0,0 +1,60 @@
|
||||
<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>
|
||||
61
Password Manager/MainForm.Designer.cs
generated
61
Password Manager/MainForm.Designer.cs
generated
@@ -29,29 +29,34 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
searchBox = new TextBox();
|
||||
resultList = new ResultListBox();
|
||||
resultList = new PasswordListBox();
|
||||
profileSelection = new ComboBox();
|
||||
addProfile = new Button();
|
||||
removeProfile = new Button();
|
||||
generatePassword = new Button();
|
||||
SuspendLayout();
|
||||
//
|
||||
// searchBox
|
||||
//
|
||||
searchBox.Location = new Point(12, 27);
|
||||
searchBox.Location = new Point(10, 20);
|
||||
searchBox.Margin = new Padding(3, 2, 3, 2);
|
||||
searchBox.Name = "searchBox";
|
||||
searchBox.PlaceholderText = "Search for a password";
|
||||
searchBox.Size = new Size(257, 27);
|
||||
searchBox.Size = new Size(225, 23);
|
||||
searchBox.TabIndex = 0;
|
||||
searchBox.TextChanged += resultList.ReloadResults;
|
||||
//
|
||||
// resultList
|
||||
//
|
||||
resultList.FormattingEnabled = true;
|
||||
resultList.ItemHeight = 20;
|
||||
resultList.Location = new Point(12, 60);
|
||||
resultList.ItemHeight = 15;
|
||||
resultList.Location = new Point(10, 45);
|
||||
resultList.Margin = new Padding(3, 2, 3, 2);
|
||||
resultList.Name = "resultList";
|
||||
resultList.Size = new Size(257, 364);
|
||||
resultList.Size = new Size(225, 274);
|
||||
resultList.TabIndex = 1;
|
||||
resultList.CurrentProfilePathRequest += CurrentProfilePathRequest;
|
||||
resultList.SearchQueryRequest += () => searchBox.Text;
|
||||
//
|
||||
// profileSelection
|
||||
//
|
||||
@@ -60,17 +65,19 @@
|
||||
profileSelection.DropDownWidth = 200;
|
||||
profileSelection.FormattingEnabled = true;
|
||||
profileSelection.IntegralHeight = false;
|
||||
profileSelection.Location = new Point(586, 26);
|
||||
profileSelection.Location = new Point(513, 20);
|
||||
profileSelection.Margin = new Padding(3, 2, 3, 2);
|
||||
profileSelection.Name = "profileSelection";
|
||||
profileSelection.Size = new Size(200, 28);
|
||||
profileSelection.Size = new Size(176, 23);
|
||||
profileSelection.TabIndex = 2;
|
||||
profileSelection.SelectedIndexChanged += ProfileHandler.ProfileChange;
|
||||
profileSelection.SelectionChangeCommitted += ChangeProfile;
|
||||
//
|
||||
// addProfile
|
||||
//
|
||||
addProfile.Location = new Point(586, 60);
|
||||
addProfile.Location = new Point(513, 45);
|
||||
addProfile.Margin = new Padding(3, 2, 3, 2);
|
||||
addProfile.Name = "addProfile";
|
||||
addProfile.Size = new Size(95, 29);
|
||||
addProfile.Size = new Size(83, 22);
|
||||
addProfile.TabIndex = 3;
|
||||
addProfile.Text = "Add";
|
||||
addProfile.UseVisualStyleBackColor = true;
|
||||
@@ -78,23 +85,36 @@
|
||||
//
|
||||
// removeProfile
|
||||
//
|
||||
removeProfile.Location = new Point(691, 60);
|
||||
removeProfile.Location = new Point(605, 45);
|
||||
removeProfile.Margin = new Padding(3, 2, 3, 2);
|
||||
removeProfile.Name = "removeProfile";
|
||||
removeProfile.Size = new Size(95, 29);
|
||||
removeProfile.Size = new Size(83, 22);
|
||||
removeProfile.TabIndex = 4;
|
||||
removeProfile.Text = "Delete";
|
||||
removeProfile.UseVisualStyleBackColor = true;
|
||||
//
|
||||
// button1
|
||||
//
|
||||
generatePassword.Location = new Point(241, 20);
|
||||
generatePassword.Name = "button1";
|
||||
generatePassword.Size = new Size(75, 23);
|
||||
generatePassword.TabIndex = 5;
|
||||
generatePassword.Text = "Generate";
|
||||
generatePassword.UseVisualStyleBackColor = true;
|
||||
generatePassword.Click += Generate;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
ClientSize = new Size(700, 338);
|
||||
Controls.Add(generatePassword);
|
||||
Controls.Add(removeProfile);
|
||||
Controls.Add(addProfile);
|
||||
Controls.Add(profileSelection);
|
||||
Controls.Add(resultList);
|
||||
Controls.Add(searchBox);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "MainForm";
|
||||
Text = "Password Manager";
|
||||
ResumeLayout(false);
|
||||
@@ -103,10 +123,11 @@
|
||||
|
||||
#endregion
|
||||
|
||||
public TextBox searchBox;
|
||||
public ResultListBox resultList;
|
||||
public ComboBox profileSelection;
|
||||
public Button addProfile;
|
||||
public Button removeProfile;
|
||||
private TextBox searchBox;
|
||||
private PasswordListBox resultList;
|
||||
private ComboBox profileSelection;
|
||||
private Button addProfile;
|
||||
private Button removeProfile;
|
||||
private Button generatePassword;
|
||||
}
|
||||
}
|
||||
@@ -1,24 +1,61 @@
|
||||
namespace Password_Manager
|
||||
{
|
||||
public delegate void ProfileChanges(string profileName);
|
||||
public delegate string[] ProfileList();
|
||||
public delegate void Save();
|
||||
public partial class MainForm : Form
|
||||
{
|
||||
public MainForm()
|
||||
public event ProfileDataRequest? CurrentProfilePathRequest;
|
||||
public event ProfileDataRequest? CurrentProfileNameRequest;
|
||||
public event ProfileList? CurrentProfileListRequest;
|
||||
public event ProfileChanges? CurrentProfileChanged;
|
||||
public event Save? SaveRequest;
|
||||
|
||||
public MainForm(ProfileDataRequest CurrentProfileNameRequest, ProfileDataRequest CurrentProfilePathRequest, ProfileList CurrentProfileListRequest, ProfileChanges CurrentProfileChanged)
|
||||
{
|
||||
this.CurrentProfileNameRequest = CurrentProfileNameRequest;
|
||||
this.CurrentProfilePathRequest = CurrentProfilePathRequest;
|
||||
this.CurrentProfileListRequest = CurrentProfileListRequest;
|
||||
this.CurrentProfileChanged = CurrentProfileChanged;
|
||||
InitializeComponent();
|
||||
LoadCurrentProfile();
|
||||
|
||||
foreach (string s in CurrentProfileListRequest?.Invoke())
|
||||
{
|
||||
profileSelection.Items.Add(s);
|
||||
}
|
||||
profileSelection.SelectedIndex = 0;
|
||||
|
||||
SaveRequest?.Invoke();
|
||||
}
|
||||
|
||||
private void LoadCurrentProfile()
|
||||
{
|
||||
this.Text = CurrentProfileNameRequest?.Invoke();
|
||||
resultList.ReloadResults();
|
||||
}
|
||||
|
||||
private void ChangeProfile(object sender, EventArgs e)
|
||||
{
|
||||
ComboBox cb = (ComboBox)sender;
|
||||
ProfileHandler.CurrentProfile = ProfileHandler.ListOfProfiles.SearchByName(cb.Text);
|
||||
searchBox.Clear();
|
||||
this.Text = ProfileHandler.CurrentProfile == null ? "Password Manager" : $"Current profile: {ProfileHandler.CurrentProfile.Name}";
|
||||
CurrentProfileChanged?.Invoke(profileSelection.Text);
|
||||
|
||||
foreach (string s in CurrentProfileListRequest?.Invoke())
|
||||
{
|
||||
profileSelection.Items.Add(s);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddProfile(object sender, EventArgs e)
|
||||
{
|
||||
NewProfileForm npf = new NewProfileForm();
|
||||
npf.ReloadPasswordsRequest += () => resultList.ReloadResults();
|
||||
npf.Show();
|
||||
}
|
||||
|
||||
private void Generate(object sender, EventArgs e)
|
||||
{
|
||||
GeneratePassword gp = new GeneratePassword(searchBox.Text, CurrentProfilePathRequest?.Invoke());
|
||||
gp.Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Data;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Password_Manager
|
||||
{
|
||||
public delegate void NewProfile(string profileName, string profilePath);
|
||||
public delegate void ReloadPasswords();
|
||||
public partial class NewProfileForm : Form
|
||||
{
|
||||
public event NewProfile NewProfileRequest;
|
||||
public event ReloadPasswords ReloadPasswordsRequest;
|
||||
|
||||
public NewProfileForm()
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -30,10 +25,8 @@ namespace Password_Manager
|
||||
{
|
||||
if (nameTextBox.Text != "" && pathTextBox.Text != "")
|
||||
{
|
||||
Profile profile = new Profile(nameTextBox.Text, pathTextBox.Text);
|
||||
ProfileHandler.ListOfProfiles.Add(profile);
|
||||
ProfileHandler.CurrentProfile = profile;
|
||||
Program.mainForm.resultList.ReloadResults();
|
||||
NewProfileRequest?.Invoke(nameTextBox.Text, pathTextBox.Text);
|
||||
ReloadPasswordsRequest?.Invoke();
|
||||
this.Close();
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,13 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Compile Update="GeneratePassword.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Update="MainForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Update="NewProfileForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
<Compile Update="ResultListBox.cs">
|
||||
<Compile Update="PasswordListBox.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
|
||||
34
Password Manager/PasswordGenerator.cs
Normal file
34
Password Manager/PasswordGenerator.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System.Text;
|
||||
|
||||
namespace Password_Generator
|
||||
{
|
||||
static class Generator
|
||||
{
|
||||
public static string New(int length, bool no_symbols = false)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Random rnd = new Random();
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
if (rnd.Next(0, 101) <= 60) //60% chance for a character
|
||||
{
|
||||
char c = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rnd.NextDouble() + 65))); //random character
|
||||
if (no_symbols && Char.IsSymbol(c))
|
||||
{
|
||||
while (Char.IsSymbol(c))
|
||||
{
|
||||
c = Convert.ToChar(Convert.ToInt32(Math.Floor(26 * rnd.NextDouble() + 65))); //random character
|
||||
}
|
||||
}
|
||||
builder.Append(c);
|
||||
}
|
||||
else //40% change for number
|
||||
{
|
||||
builder.Append(Convert.ToChar(rnd.Next(0, 10)));
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
47
Password Manager/PasswordListBox.cs
Normal file
47
Password Manager/PasswordListBox.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
namespace Password_Manager
|
||||
{
|
||||
public delegate string SearchQuery();
|
||||
public class PasswordListBox : ListBox
|
||||
{
|
||||
public event ProfileDataRequest? CurrentProfilePathRequest;
|
||||
public event SearchQuery? SearchQueryRequest;
|
||||
|
||||
public PasswordListBox() : base() { }
|
||||
|
||||
public void ReloadResults(object sender = null, EventArgs arg = null)
|
||||
{
|
||||
DirectoryInfo d;
|
||||
FileInfo[] files = new FileInfo[0];
|
||||
try
|
||||
{
|
||||
d = new DirectoryInfo(CurrentProfilePathRequest?.Invoke());
|
||||
files = d.GetFiles("*.gpg");
|
||||
} catch (ArgumentNullException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "Error: Invalid profile path", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
string[] arrayTmp = new string[files.Length];
|
||||
for (int i = 0; i < arrayTmp.Length; i++)
|
||||
{
|
||||
arrayTmp[i] = files[i].Name;
|
||||
}
|
||||
List<string> elements = new List<string>(arrayTmp);
|
||||
|
||||
string[] copy = elements.ToArray();
|
||||
string searchQuery = SearchQueryRequest?.Invoke();
|
||||
if (searchQuery != "") //we have a search query
|
||||
{
|
||||
foreach (string s in copy)
|
||||
{
|
||||
if (!s.Contains(searchQuery))
|
||||
{
|
||||
elements.Remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.DataSource = elements;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Profiles
|
||||
{
|
||||
abstract class IList<T>
|
||||
{
|
||||
@@ -1,10 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Profiles
|
||||
{
|
||||
public delegate void PasswordStoreChange();
|
||||
|
||||
sealed class Profile
|
||||
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
|
||||
|
||||
@@ -1,17 +1,89 @@
|
||||
using System;
|
||||
using Password_Manager;
|
||||
using Microsoft.VisualBasic.FileIO;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Profiles
|
||||
{
|
||||
static class ProfileHandler
|
||||
{
|
||||
public static Profile CurrentProfile;
|
||||
public static ProfileList ListOfProfiles;
|
||||
private static string filePath = SpecialDirectories.CurrentUserApplicationData + "Profiles.csv";
|
||||
|
||||
public static void ProfileChange(object sender, EventArgs e)
|
||||
public static void ChangeProfiles(string profileName)
|
||||
{
|
||||
Program.mainForm.searchBox.Clear();
|
||||
Program.mainForm.resultList.ReloadResults();
|
||||
Program.mainForm.profileSelection.DataSource = ListOfProfiles;
|
||||
CurrentProfile = ListOfProfiles.SearchByName(profileName);
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
{
|
||||
ListOfProfiles = new ProfileList();
|
||||
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
LoadProfiles();
|
||||
}
|
||||
else
|
||||
{
|
||||
CreateProfiles();
|
||||
}
|
||||
}
|
||||
private static void LoadProfiles()
|
||||
{
|
||||
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();
|
||||
CreateProfiles();
|
||||
break;
|
||||
}
|
||||
}
|
||||
sr.Close();
|
||||
} catch (IOException e)
|
||||
{
|
||||
MessageBox.Show(e.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TrimLastLine()
|
||||
{
|
||||
List<string> lines = File.ReadAllLines(filePath).ToList();
|
||||
File.WriteAllLines(filePath, lines.GetRange(0, lines.Count - 1).ToArray());
|
||||
}
|
||||
|
||||
private static void CreateProfiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(filePath);
|
||||
|
||||
string[] parameters = new string[2];
|
||||
|
||||
NewProfileForm np = new NewProfileForm();
|
||||
Profile firstProfile = null;
|
||||
np.NewProfileRequest += (string profileName, string profilePath) =>
|
||||
{
|
||||
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,6 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Profiles
|
||||
{
|
||||
sealed class ProfileList : IList<Profile>
|
||||
{
|
||||
@@ -59,5 +57,15 @@ namespace Password_Manager
|
||||
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,7 +1,4 @@
|
||||
using System;
|
||||
using System.Runtime.CompilerServices;
|
||||
|
||||
namespace Password_Manager
|
||||
namespace Profiles
|
||||
{
|
||||
sealed class ProfileNotFoundException : Exception
|
||||
{
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using Profiles;
|
||||
|
||||
namespace Password_Manager
|
||||
{
|
||||
public delegate string ProfileDataRequest();
|
||||
internal static class Program
|
||||
{
|
||||
/// <summary>
|
||||
@@ -8,11 +11,17 @@ namespace Password_Manager
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
ProfileHandler.ListOfProfiles = new ProfileList();
|
||||
ApplicationConfiguration.Initialize();
|
||||
ProfileHandler.Init();
|
||||
|
||||
Application.Run(mainForm);
|
||||
}
|
||||
|
||||
public static MainForm mainForm = new MainForm();
|
||||
public static MainForm mainForm = new MainForm(
|
||||
() => ProfileHandler.CurrentProfile.Name,
|
||||
() => ProfileHandler.CurrentProfile.Path,
|
||||
() => ProfileHandler.ListOfProfiles.GetNameList(),
|
||||
(profileName) => ProfileHandler.ChangeProfiles(profileName)
|
||||
); //needed at creation so that MainForm may pass this method down to other classes in its constructor
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace Password_Manager
|
||||
{
|
||||
public class ResultListBox : ListBox
|
||||
{
|
||||
public ResultListBox() : base() { }
|
||||
|
||||
public void ReloadResults()
|
||||
{
|
||||
DirectoryInfo d = new DirectoryInfo(ProfileHandler.CurrentProfile.Path);
|
||||
FileInfo[] files = d.GetFiles("*.gpg");
|
||||
string[] arrayTmp = new string[files.Length];
|
||||
for (int i = 0; i < arrayTmp.Length; i++)
|
||||
{
|
||||
arrayTmp[i] = files[i].Name;
|
||||
}
|
||||
List<string> elements = new List<string>(arrayTmp);
|
||||
|
||||
string[] copy = elements.ToArray();
|
||||
if (Program.mainForm.searchBox.Text != "") //we have a search query
|
||||
{
|
||||
foreach (string s in copy)
|
||||
{
|
||||
if (!s.Contains(Program.mainForm.searchBox.Text))
|
||||
{
|
||||
elements.Remove(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.DataSource = elements;
|
||||
}
|
||||
|
||||
public void ReloadResults(object o, EventArgs e) //needed so that I can subscribe this method to a delegate in MainForm
|
||||
{
|
||||
ReloadResults();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@ build_property.PlatformNeutralAssembly =
|
||||
build_property.EnforceExtendedAnalyzerRules =
|
||||
build_property._SupportedPlatformList = Linux,macOS,Windows
|
||||
build_property.RootNamespace = Password_Manager
|
||||
build_property.ProjectDir = C:\Users\RichardMiskolczi\Password Manager\Password Manager\
|
||||
build_property.ProjectDir = C:\Users\Typo\Projects\Windows-Password-Manager\Password Manager\
|
||||
|
||||
Binary file not shown.
@@ -12,8 +12,8 @@
|
||||
}
|
||||
],
|
||||
"additionalProbingPaths": [
|
||||
"C:\\Users\\RichardMiskolczi\\.dotnet\\store\\|arch|\\|tfm|",
|
||||
"C:\\Users\\RichardMiskolczi\\.nuget\\packages"
|
||||
"C:\\Users\\Typo\\.dotnet\\store\\|arch|\\|tfm|",
|
||||
"C:\\Users\\Typo\\.nuget\\packages"
|
||||
],
|
||||
"configProperties": {
|
||||
"Microsoft.NETCore.DotNetHostPolicy.SetAppPaths": true
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
{
|
||||
"format": 1,
|
||||
"restore": {
|
||||
"C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj": {}
|
||||
"C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj": {}
|
||||
},
|
||||
"projects": {
|
||||
"C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj": {
|
||||
"C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj",
|
||||
"projectUniqueName": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj",
|
||||
"projectName": "Password Manager",
|
||||
"projectPath": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj",
|
||||
"packagesPath": "C:\\Users\\RichardMiskolczi\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\obj\\",
|
||||
"projectPath": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj",
|
||||
"packagesPath": "C:\\Users\\Typo\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\RichardMiskolczi\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Users\\Typo\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
|
||||
@@ -5,11 +5,11 @@
|
||||
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
|
||||
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
|
||||
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\RichardMiskolczi\.nuget\packages\</NuGetPackageFolders>
|
||||
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\Typo\.nuget\packages\</NuGetPackageFolders>
|
||||
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
|
||||
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">6.5.0</NuGetToolVersion>
|
||||
</PropertyGroup>
|
||||
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
|
||||
<SourceRoot Include="C:\Users\RichardMiskolczi\.nuget\packages\" />
|
||||
<SourceRoot Include="C:\Users\Typo\.nuget\packages\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -8,19 +8,19 @@
|
||||
"net7.0-windows7.0": []
|
||||
},
|
||||
"packageFolders": {
|
||||
"C:\\Users\\RichardMiskolczi\\.nuget\\packages\\": {}
|
||||
"C:\\Users\\Typo\\.nuget\\packages\\": {}
|
||||
},
|
||||
"project": {
|
||||
"version": "1.0.0",
|
||||
"restore": {
|
||||
"projectUniqueName": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj",
|
||||
"projectUniqueName": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj",
|
||||
"projectName": "Password Manager",
|
||||
"projectPath": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj",
|
||||
"packagesPath": "C:\\Users\\RichardMiskolczi\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\obj\\",
|
||||
"projectPath": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj",
|
||||
"packagesPath": "C:\\Users\\Typo\\.nuget\\packages\\",
|
||||
"outputPath": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\obj\\",
|
||||
"projectStyle": "PackageReference",
|
||||
"configFilePaths": [
|
||||
"C:\\Users\\RichardMiskolczi\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Users\\Typo\\AppData\\Roaming\\NuGet\\NuGet.Config",
|
||||
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
|
||||
],
|
||||
"originalTargetFrameworks": [
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"version": 2,
|
||||
"dgSpecHash": "j+Af3msCh5F346C/nQWI7qovMW8Vd2PEbp7ynx42JtS4tfpFIR2p1HtRmEyrqVdFgQ1kz/RvVO6rZ8LL+kAtoA==",
|
||||
"dgSpecHash": "pORlMyjnmPISFrdLakbVEwbRIXTIF7StLLdawRpMvRY01tBOhcBNA+U3VV7qwceV2a898Rx6Vw+s/NGbmgKQVQ==",
|
||||
"success": true,
|
||||
"projectFilePath": "C:\\Users\\RichardMiskolczi\\Password Manager\\Password Manager\\Password Manager.csproj",
|
||||
"projectFilePath": "C:\\Users\\Typo\\Projects\\Windows-Password-Manager\\Password Manager\\Password Manager.csproj",
|
||||
"expectedPackageFiles": [],
|
||||
"logs": []
|
||||
}
|
||||
Reference in New Issue
Block a user