This commit is contained in:
2023-03-28 08:22:08 +02:00
parent 35db2e56d4
commit f08b2e91c8
5 changed files with 62 additions and 12 deletions

View File

@@ -15,20 +15,21 @@ namespace Password_Manager
public void Generate(object sender, EventArgs e)
{
if (passwordName.Text == "" && passwordLength.Text == "")
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)
else
{
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();
string filePath = $"{currentPath}\\{passwordName.Text}";
File.WriteAllText(
currentPath + $"\\{passwordName.Text}.gpg",
PasswordGenerator.New(
Convert.ToInt32(passwordLength.Text),
noSymbols.Checked)
);
}
catch (FormatException)
{