Use a predetermined default password length field
This commit is contained in:
@@ -4,7 +4,8 @@ namespace Common;
|
||||
public static class PasswordGenerator
|
||||
{
|
||||
public static Error? ExceptionOccured;
|
||||
private static string RandomStr(int length, bool no_symbols = false)
|
||||
public static int DEFAULT_LENGTH = 16;
|
||||
private static string RandomStr(int length = 16, bool no_symbols = false)
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
Random rnd = new Random();
|
||||
|
||||
2
GUI/GeneratePassword.Designer.cs
generated
2
GUI/GeneratePassword.Designer.cs
generated
@@ -67,7 +67,7 @@ partial class GeneratePassword
|
||||
//
|
||||
passwordLength.Location = new Point(12, 77);
|
||||
passwordLength.Name = "passwordLength";
|
||||
passwordLength.PlaceholderText = "16";
|
||||
passwordLength.PlaceholderText = PasswordGenerator.DEFAULT_LENGTH;
|
||||
passwordLength.Size = new Size(156, 23);
|
||||
passwordLength.TabIndex = 3;
|
||||
//
|
||||
|
||||
@@ -19,21 +19,28 @@ public partial class GeneratePassword : Form
|
||||
|
||||
public void Generate(object sender, EventArgs e)
|
||||
{
|
||||
if (passwordName.Text == "" || passwordLength.Text == "")
|
||||
if (passwordName.Text == "")
|
||||
{
|
||||
MessageBox.Show("You must fill in all fields to continue.", "Error: Empty fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
MessageBox.Show("You must provide a name to continue.", "Error: Empty field", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
int length;
|
||||
if (!int.TryParse(passwordLength.Text, out length))
|
||||
{
|
||||
length = PasswordGenerator.DEFAULT_LENGTH
|
||||
}
|
||||
|
||||
PasswordGenerator.ExceptionOccured += (e) => MessageBox.Show(e.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
string filePath = $"{currentPath}\\{passwordName.Text}";
|
||||
File.WriteAllText(
|
||||
currentPath + $"\\{passwordName.Text}.gpg",
|
||||
PasswordGenerator.New(
|
||||
recipient,
|
||||
Convert.ToInt32(passwordLength.Text),
|
||||
length,
|
||||
noSymbols.Checked)
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user