2023-03-27 00:19:30 +02:00
|
|
|
|
using Password_Generator;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Password_Manager
|
|
|
|
|
|
{
|
2023-03-28 13:25:26 +02:00
|
|
|
|
public delegate void MethodRequest();
|
2023-03-27 00:19:30 +02:00
|
|
|
|
public partial class GeneratePassword : Form
|
|
|
|
|
|
{
|
|
|
|
|
|
private string currentPath;
|
2023-03-28 13:10:57 +02:00
|
|
|
|
private string recipient;
|
2023-03-28 13:25:26 +02:00
|
|
|
|
public MethodRequest ReloadRequest;
|
2023-03-27 00:19:30 +02:00
|
|
|
|
|
2023-03-28 13:25:26 +02:00
|
|
|
|
public GeneratePassword(string currentPath, string recipient, MethodRequest ReloadRequest, string? name)
|
2023-03-27 00:19:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
passwordName.Text = name;
|
|
|
|
|
|
this.currentPath = currentPath;
|
2023-03-28 13:10:57 +02:00
|
|
|
|
this.recipient = recipient;
|
2023-03-28 13:25:26 +02:00
|
|
|
|
this.ReloadRequest = ReloadRequest;
|
2023-03-27 00:19:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Generate(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2023-03-28 08:22:08 +02:00
|
|
|
|
if (passwordName.Text == "" || passwordLength.Text == "")
|
2023-03-27 00:19:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
|
|
|
|
|
}
|
2023-03-28 08:22:08 +02:00
|
|
|
|
else
|
2023-03-27 00:19:30 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2023-03-28 08:22:08 +02:00
|
|
|
|
string filePath = $"{currentPath}\\{passwordName.Text}";
|
|
|
|
|
|
File.WriteAllText(
|
|
|
|
|
|
currentPath + $"\\{passwordName.Text}.gpg",
|
|
|
|
|
|
PasswordGenerator.New(
|
2023-03-28 13:10:57 +02:00
|
|
|
|
recipient,
|
2023-03-28 08:22:08 +02:00
|
|
|
|
Convert.ToInt32(passwordLength.Text),
|
|
|
|
|
|
noSymbols.Checked)
|
|
|
|
|
|
);
|
2023-03-27 00:19:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-28 13:25:26 +02:00
|
|
|
|
ReloadRequest();
|
|
|
|
|
|
Close();
|
2023-03-27 00:19:30 +02:00
|
|
|
|
}
|
2023-03-28 13:10:57 +02:00
|
|
|
|
|
|
|
|
|
|
private void cancel_Click(object sender, EventArgs e)
|
|
|
|
|
|
{
|
|
|
|
|
|
Close();
|
|
|
|
|
|
}
|
2023-03-27 00:19:30 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|