kill me
This commit is contained in:
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user