Adding method for password generation
This commit is contained in:
@@ -28,6 +28,12 @@ class Program
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "new":
|
||||||
|
if (New() == 1)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
HelpMessage();
|
HelpMessage();
|
||||||
break;
|
break;
|
||||||
@@ -37,6 +43,61 @@ class Program
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int Generate(string name, string length = PasswordGenerator.DEFAULT_LENGTH.ToString(), string symbols = 'true')
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//do not save output, just check if exceptions are thrown
|
||||||
|
Convert.ToInt32(length);
|
||||||
|
Convert.ToBoolean(symbols);
|
||||||
|
|
||||||
|
PasswordGenerator.ExceptionOccured += (e) => ErrorOccured(e, "There was a problem generating your password. See details");
|
||||||
|
|
||||||
|
File.WriteAllText(
|
||||||
|
$"{ConfigFileManager.GetPath()}\\{name}",
|
||||||
|
PasswordGenerator.New(
|
||||||
|
ConfigFileManager.GetRecipient(),
|
||||||
|
length,
|
||||||
|
symbols
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
catch (FormatException e)
|
||||||
|
{
|
||||||
|
ErrorOccured(e, "Please provide valid parameters:\n\t- length:\tnumber\n\t- symbols\ttrue|false)");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
catch (IOException e)
|
||||||
|
{
|
||||||
|
ErrorOccured(e, "IO Error");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int New()
|
||||||
|
{
|
||||||
|
switch (args.Length)
|
||||||
|
{
|
||||||
|
case 4:
|
||||||
|
Generate(args[1], args[2], args[3]);
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
//TODO: determine if the second flag is a bool or an int
|
||||||
|
Generate(args[1], args[2]);
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
Generate(args[1]);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
//either there's an unexpected argument, or not enough
|
||||||
|
ErrorOccured(new ArgumentException(), $"Invalid or missing arguments, see '{BINARY_NAME} help'");
|
||||||
|
return 1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static int ListPasswords()
|
static int ListPasswords()
|
||||||
{
|
{
|
||||||
DirectoryInfo d;
|
DirectoryInfo d;
|
||||||
|
|||||||
Reference in New Issue
Block a user