/*Develop an applicationinC#.NET that demonstrates the registration and login
dynamically.
( two using GUI or this program )*/
using System;
using System.Collections.Generic;
namespace RegistrationLogin
{
class Program
{
static List< User> users = new List< User>();
static void Main(string[] args)
{
Console.WriteLine("Select an option:");
Console.WriteLine("1. Register");
Console.WriteLine("2. Login");
Console.WriteLine("3. Exit");
Console.Write("Enter your choice: ");
int choice = int.Parse(Console.ReadLine());
while(choice!=3){
switch (choice)
{
case 1:
Register();
break;
case 2:
Login();
break;
case 3: Console.WriteLine("Program Closed"); break;
default:
Console.WriteLine("Invalid option. Try again.");
break;
}
Console.Write("Enter your choice: ");
choice = int.Parse(Console.ReadLine());
}
}
static void Register()
{
Console.Write("Enter your username: ");
string username = Console.ReadLine();
Console.Write("Enter your password: ");
string password = Console.ReadLine();
User user = new User(username, password);
users.Add(user);
Console.WriteLine("Registration successful.");
}
static void Login()
{
Console.Write("Enter your username: ");
string username = Console.ReadLine();
Console.Write("Enter your password: ");
string password = Console.ReadLine();
foreach (User user in users)
{
if (user.Username == username && user.Password == password)
{
Console.WriteLine("Login successful.");
return;
}
}
Console.WriteLine("Login failed.");
}
}
class User
{
public string Username { get; set; }
public string Password { get; set; }
public User(string username, string password)
{
this.Username = username;
this.Password = password;
}
}
}