This is just the UI. The logic is fine.
C#:
static void Main(string[] args)
{
Console.WriteLine("This is a passwordgenerator.");
Console.WriteLine("Enter the length of your password (12 signs recommended): ");
int length;
try
{
length = int.Parse(Console.ReadLine());
}
catch (Exception)
{
Console.WriteLine("Invalid input. The program will generate a password with 12 signs.");
length = 12;
}
Console.WriteLine("Uppercase letters? (y/n): ");
char upperCase;
try { upperCase = char.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Invalid input. Program will use (y)"); upperCase = 'y'; }
bool containsUpperCase;
if (upperCase == 'y') { containsUpperCase = true; } else if (upperCase == 'n') { containsUpperCase = false; } else { containsUpperCase = false; Console.WriteLine("Invalid input. Program will use (y)"); }
Console.WriteLine("Other signs? (y/n): ");
char sign;
try { sign = char.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Invalid input. Program will use (y)"); sign = 'y'; }
bool containsSign;
if (sign == 'y') { containsSign = true; } else if (sign == 'n') { containsSign = false; } else { containsSign = false; Console.WriteLine("Invalid input. Program will use (y)"); }
Console.WriteLine("Numbers? (y/n): ");
char number;
try { number = char.Parse(Console.ReadLine()); } catch (Exception) { Console.WriteLine("Invalid input. Program will use (y)"); number = 'y'; }
bool containsNumber;
if (number == 'y') { containsNumber = true; } else if (number == 'n') { containsNumber = false; } else { containsNumber = false; Console.WriteLine("Invalid input. Program will use (y)"); }
}