Create an application which consist of following module:a.Signup Panel which consists of user required fields (username, password, Email,Address, phone).
b.After Signup user must login with Id and password while ID must be generated automatically when you signup and generate the unique id in database.
c.Email address must be valid by using email address pattern by Regex.
d.Phone number field must be numeric we cannot enter string in phone.
e.Username must contain characters.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Text.RegularExpressions;
namespace Q216966
{
class Account {
public int ID{ get; set; }
public string Username{get;set;}
public string Password{get;set;}
public string Email{get;set;}
public string Address{get;set;}
public string Phone{get;set;}
public void display() {
Console.WriteLine("ID: {0}", ID);
Console.WriteLine("Username: {0}", Username);
Console.WriteLine("Password: {0}", Password);
Console.WriteLine("Email: {0}", Email);
Console.WriteLine("Address: {0}", Address);
Console.WriteLine("Phone: {0}", Phone);
}
public bool isLogin(int ID, string password)
{
return ((this.ID == ID) && (this.Password == password));
}
}
class Program{
static void Main(string[] args){
List<Account> accounts = new List<Account>();
Random rand = new Random();
int ch=-1;
while(ch!=3){
Console.WriteLine("1. Signup");
Console.WriteLine("2. Login");
Console.WriteLine("3. Exit");
Console.Write("Your choice: ");
int.TryParse(Console.ReadLine(), out ch);
if (ch == 1) {
// ID must be generated automatically when you signup and generate the unique id in database.
Account newAccount = new Account();
newAccount.ID = rand.Next(1000, 10000);
Console.WriteLine("ID: {0}", newAccount.ID);
newAccount.Username = " ";
while (newAccount.Username == " ")
{
Console.Write("Enter username: ");
newAccount.Username = Console.ReadLine();
Regex usernameRegex = new Regex(@"^[a-zA-Z]+$");
Match match = usernameRegex.Match(newAccount.Username);
if (!match.Success){
Console.WriteLine("Username is wrong.\n");
newAccount.Username = " ";
}
}
Console.Write("Enter password: ");
newAccount.Password = Console.ReadLine();
newAccount.Email = " ";
while (newAccount.Email == " ")
{
Console.Write("Enter email: ");
newAccount.Email = Console.ReadLine();
Regex usernameRegex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");
Match match = usernameRegex.Match(newAccount.Email);
if (!match.Success)
{
Console.WriteLine("Email is wrong.\n");
newAccount.Email = " ";
}
}
Console.Write("Enter address: ");
newAccount.Address = Console.ReadLine();
newAccount.Phone = " ";
while (newAccount.Phone == " ")
{
Console.Write("Enter phone: ");
newAccount.Phone = Console.ReadLine();
Regex phoneRegex = new Regex(@"^[0-9]+$");
Match match = phoneRegex.Match(newAccount.Phone);
if (!match.Success)
{
Console.WriteLine("Phone is wrong.\n");
newAccount.Phone = " ";
}
}
accounts.Add(newAccount);
}
else if (ch == 2)
{
Console.Write("Enter ID: ");
int ID;
int.TryParse(Console.ReadLine(), out ID);
Console.Write("Enter password: ");
string password = Console.ReadLine();
for (int i = 0; i < accounts.Count; i++) {
if (accounts[i].isLogin(ID, password))
{
accounts[i].display();
break;
}
}
}
else if (ch == 3)
{
//exit
}
else {
Console.WriteLine("\nWrong menu item.\n");
}
}
Console.ReadLine();
}
}
}
Comments
Leave a comment