Simplified password generation.

The class is called PasswordGenerator, so that's what it will *only* do
This commit is contained in:
2023-03-28 10:13:44 +02:00
parent 2b5880dbce
commit cd69c18f56

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Text;
using System.Text;
namespace Password_Generator
{
@@ -32,10 +31,8 @@ namespace Password_Generator
return builder.ToString();
}
public static string New(int length, bool no_symbols = false)
public static string New(string recipient, int length, bool no_symbols = false)
{
File.WriteAllText(@".\\", RandomStr(length, no_symbols));
try
{
Process proc = new Process()
@@ -43,7 +40,7 @@ namespace Password_Generator
StartInfo = new ProcessStartInfo
{
FileName = "echo", //TODO: pipe the return value of RandomStr to gpg with the --quiet --encrypt --recipient {recipient} flags
//Arguments = $"--quiet --decrypt {filePath}",
Arguments = $"{RandomStr(length, no_symbols)} | gpg --quiet --encrypt --recipient {recipient}",
UseShellExecute = false,
RedirectStandardOutput = true,
CreateNoWindow = true
@@ -51,19 +48,20 @@ namespace Password_Generator
};
proc.Start();
StringBuilder builder = new StringBuilder();
while (!proc.StandardOutput.EndOfStream)
{
string line = proc.StandardOutput.ReadLine();
Clipboard.SetText(line);
//Process.Start("./ToastNotification.exe", $"\"{fileName} decrypted\" \"Password copied to clipboard\"");
builder.Append(proc.StandardOutput.ReadLine());
return builder.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return null;
}
return null;
}
}
}