Вход в систему из консольного приложения C# при новой регистрацииC#

Место общения программистов C#
Anonymous
Вход в систему из консольного приложения C# при новой регистрации

Сообщение Anonymous »

Я учусь на программе Разработка программного обеспечения и работаю над вторым заданием, так что все еще новичок. У меня есть некоторые проблемы с выяснением того, как войти в систему с моей новой регистрационной информацией, и я не знаю, как это сделать.
Я все еще дорабатываю свой код регистрации, чтобы отображать сообщения об ошибках с пробелами. или пустые записи, поэтому, пожалуйста, не судите. Я еще не добавил никаких комментариев.
Моя основная проблема заключается в использовании новых данных для последующего входа пользователя в систему (я думаю).
Приношу извинения за загрузку всего если это кажется очень длинным, но я впервые использую этот сайт для публикации.
Основная вкладка программы:

Код: Выделить всё

class BankAccount
{
public static void MainMenu()
{
Console.Clear();
Console.WriteLine("Welcome to Bam's Bank of NSW. \nPlease select from the following menu: \n1: Login \n2: Sign up \n3: Quit");

int input = Convert.ToInt32(Console.ReadLine());

switch (input)
{
case 1:
Login();
break;

case 2:
SignUp();
break;

case 3:
Program.Quit();
break;
}
}

public static void WelcomeMenu()
{
Console.Clear();
Console.WriteLine("Welcome John \nPlease select from the following menu: \n1: View Balance \n2: Deposit \n3: Withdraw \n4: Transfer \n5: Quit");

int input1 = Convert.ToInt32(Console.ReadLine());

switch (input1)
{
case 1:
Bank.ViewBalance();
break;

case 2:
Bank.Deposit();
break;

case 3:
Bank.Withdraw();
break;

case 4:
Bank.Transfer();
break;

case 5:
Program.Quit();
break;
}
}

public static void SignUp()
{
Console.Clear();
Console.WriteLine("Thank you for choosing Bam bank of NSW.\nPlease enter your details to open a new account\n");
Console.WriteLine("Please enter your name");

string name = Console.ReadLine();

Console.WriteLine("Enter your Email. This will become your Username:");

string email = Console.ReadLine();

if (email == "")
{
Console.WriteLine("Cannot be blank.");
}

Console.WriteLine("Please enter your Age:");
int age = Convert.ToInt32(Console.ReadLine());

if (age < 18)
{
Console.WriteLine("To open an account you need to be 18yrs.");
}

Console.WriteLine("Please create a password:");
string password = Console.ReadLine();

if (password == "")
{
Console.WriteLine("Cannot be blank.");
}

Console.WriteLine($"Account successfully created for {email}. Please login");

Accounts accounts = new Accounts();
accounts.Name = name;
accounts.Email = email;
accounts.Age = age;
accounts.Password = password;
Accounts.AllAccounts.Add(accounts);

Console.ReadKey();
Login();
}

public static void Login()
{
Console.Clear();
Console.WriteLine("Please enter your email/username");

string uname = Console.ReadLine();
Accounts accounts = new Accounts();

if (uname == accounts.Email)
{
Console.WriteLine("Please enter your Password");
}
else if (uname != accounts.Email)
{
TryAgain();
}

string pword = Console.ReadLine();

if (pword == accounts.Password)
{
WelcomeMenu();
}
else if (pword != accounts.Password)
{
TryAgain();
}
}

public static void TryAgain()
{
Console.Clear();

Console.WriteLine("Invalid username/Password.  Please select a function.\n1: Try Again \n2: Main Menu \n3: Quit");

int input2 = Convert.ToInt32(Console.ReadLine());

switch (input2)
{
case 1:
Login();
break;

case 2:
MainMenu();
break;

case 3:
Program.Quit();
break;
}
}
}

class Program
{
static void Main(string[] args)
{
BankAccount.MainMenu();
}

public static void Quit()
{
Console.Clear();
Console.WriteLine("Thank you and have a nice day! \nPress any key to exit");
Console.ReadKey();
return;
}
}
Вкладка «Аккаунты»:

Код: Выделить всё

public class Accounts
{
private static List accounts = new List();

public static List AllAccounts
{
get { return accounts; }
}

public Accounts()
{
}

public string Name { get; set; }
public string Email { get; set; }
public int Age { get; set; }
public string Password { get; set; }
}
Я попробовал несколько разных кодов, некоторые ответы нашел здесь, а некоторые — на сайте Learn.microsoft.com, но мне не повезло. Если кто-нибудь сможет мне помочь, это будет здорово.

Подробнее здесь: https://stackoverflow.com/questions/788 ... onsole-app

Вернуться в «C#»