stuff
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
1
Password Manager/MainForm.Designer.cs
generated
1
Password Manager/MainForm.Designer.cs
generated
@@ -84,6 +84,7 @@
|
||||
Cancel.TabIndex = 8;
|
||||
Cancel.Text = "Cancel";
|
||||
Cancel.UseVisualStyleBackColor = true;
|
||||
Cancel.Click += CancelPressed;
|
||||
//
|
||||
// MainForm
|
||||
//
|
||||
|
||||
@@ -26,6 +26,11 @@ namespace Password_Manager
|
||||
gp.ShowDialog();
|
||||
}
|
||||
|
||||
private void CancelPressed(object sender, EventArgs e)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
private void Decrypt(object sender, EventArgs e)
|
||||
{
|
||||
string fileName = ResultList.Text;
|
||||
@@ -55,6 +60,8 @@ namespace Password_Manager
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,11 @@
|
||||
using System.Text;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Password_Generator
|
||||
{
|
||||
static class Generator
|
||||
static class PasswordGenerator
|
||||
{
|
||||
public static string New(int length, bool no_symbols = false)
|
||||
private static string RandomStr(int length, bool no_symbols = false)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Random rnd = new Random();
|
||||
@@ -30,5 +31,39 @@ namespace Password_Generator
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
public static string New(int length, bool no_symbols = false)
|
||||
{
|
||||
File.WriteAllText(@".\\", RandomStr(length, no_symbols));
|
||||
|
||||
try
|
||||
{
|
||||
Process proc = new Process()
|
||||
{
|
||||
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}",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
}
|
||||
};
|
||||
|
||||
proc.Start();
|
||||
while (!proc.StandardOutput.EndOfStream)
|
||||
{
|
||||
string line = proc.StandardOutput.ReadLine();
|
||||
Clipboard.SetText(line);
|
||||
//Process.Start("./ToastNotification.exe", $"\"{fileName} decrypted\" \"Password copied to clipboard\"");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,13 @@ namespace Password_Manager
|
||||
}
|
||||
|
||||
this.DataSource = elements;
|
||||
SelectedIndex = 0;
|
||||
try
|
||||
{
|
||||
SelectedIndex = 0;
|
||||
} catch (ArgumentOutOfRangeException)
|
||||
{
|
||||
SelectedIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user