Renamed project to GUI

This commit is contained in:
2023-04-02 21:53:39 +02:00
parent 385dda6611
commit f947949e3b
69 changed files with 483 additions and 19 deletions

58
GUI/GeneratePassword.cs Normal file
View File

@@ -0,0 +1,58 @@
using Password_Generator;
namespace Password_Manager
{
public delegate void MethodRequest();
public partial class GeneratePassword : Form
{
private string currentPath;
private string recipient;
public event MethodRequest ReloadRequest;
public GeneratePassword(string currentPath, string recipient, MethodRequest ReloadRequest, string? name)
{
InitializeComponent();
passwordName.Text = name;
this.currentPath = currentPath;
this.recipient = recipient;
this.ReloadRequest = ReloadRequest;
}
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);
}
else
{
try
{
string filePath = $"{currentPath}\\{passwordName.Text}";
File.WriteAllText(
currentPath + $"\\{passwordName.Text}.gpg",
PasswordGenerator.New(
recipient,
Convert.ToInt32(passwordLength.Text),
noSymbols.Checked)
);
}
catch (FormatException)
{
MessageBox.Show("Please enter a valid number for the password's length.", "Error: Invalid field", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
catch (IOException error)
{
MessageBox.Show(error.ToString(), "IO Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
ReloadRequest();
Close();
}
private void cancel_Click(object sender, EventArgs e)
{
Close();
}
}
}