using Password_Generator; namespace Password_Manager { public partial class GeneratePassword : Form { private string currentPath; private string recipient; public GeneratePassword(string name, string currentPath, string recipient) { InitializeComponent(); passwordName.Text = name; this.currentPath = currentPath; this.recipient = recipient; } 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); } } } } }