From cd69c18f566f6e5393156a191ac0b3dcda376f46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miskolczi=20Rich=C3=A1rd?= Date: Tue, 28 Mar 2023 10:13:44 +0200 Subject: [PATCH] Simplified password generation. The class is called PasswordGenerator, so that's what it will *only* do --- Password Manager/PasswordGenerator.cs | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Password Manager/PasswordGenerator.cs b/Password Manager/PasswordGenerator.cs index a4c44af..634e2cc 100644 --- a/Password Manager/PasswordGenerator.cs +++ b/Password Manager/PasswordGenerator.cs @@ -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; } } }