This repository has been archived on 2025-09-26. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Password-Manager-Legacy/GUI/GeneratePassword.cs

58 lines
1.9 KiB
C#
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Common;
namespace GUI;
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
{
PasswordGenerator.ExceptionOccured += (e) => MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
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();
}
}