コード例 #1
0
        public static IUser showUser(string username)
        {
            string gender = getData("Users", "username", "gender", username);
            string cars   = getData("Users", "username", "cars", username);
            string type   = getData("Users", "username", "type", username);

            if (type == "regular user")
            {
                IUser user = new RegularUser
                {
                    username = username,
                    cars     = cars,
                    type     = type
                };
                return(user);
            }
            else if (type == "dealer")
            {
                IUser user = new Dealer
                {
                    username = username,
                    cars     = cars,
                    type     = type
                };
                return(user);
            }
            else
            {
                IUser user = new Administrator();
                return(user);
            }
        }
コード例 #2
0
        public static void signUp(string username)
        {
            Console.WriteLine($"Your username is: {username}");
            //Input to show '*'
            SecureString pass     = Commands.maskInputString();
            string       Password = new System.Net.NetworkCredential(string.Empty, pass).Password;

            Console.WriteLine();
            SecureString pass2     = Commands.maskInputString();
            string       Password2 = new System.Net.NetworkCredential(string.Empty, pass2).Password;

            //User should try again in the two passwords does not match
            while (Password != Password2)
            {
                Console.WriteLine();
                Console.WriteLine("The passwords does not match. Try again!");
                SecureString pass3 = Commands.maskInputString();
                Password2 = new System.Net.NetworkCredential(string.Empty, pass3).Password;
            }

            //User enters its gender
            Console.WriteLine();
            Console.WriteLine("Enter gender: ");
            string gender = Console.ReadLine();

            //User must choose type of user
            Console.WriteLine("Choose your role: (regular user, dealer)");
            string type = Console.ReadLine();


            //Connection to the Database
            if (type == "regular user")
            {
                IUser user = new RegularUser
                {
                    username = username,
                    password = Password,
                    gender   = gender,
                    type     = type
                };
                Commands.insertUser(user);
            }
            else
            {
                IUser user = new Dealer
                {
                    username = username,
                    password = Password,
                    gender   = gender,
                    type     = type
                };

                Commands.insertUser(user);
            }
        }
コード例 #3
0
        public static IUser signIn()
        {
            Console.WriteLine("Username: "******"username", username))
            {
                Console.WriteLine("There is not such username. Please try again!");
                username = Console.ReadLine();
            }

            //User enters password
            SecureString pass     = Commands.maskInputString();
            string       Password = new System.Net.NetworkCredential(string.Empty, pass).Password;

            Console.WriteLine();

            var encryptedPassword = Commands.getData("Users", "username", "password", username);

            var splitPassSalt = encryptedPassword.Split(' ');

            //Check wheater this is the right password for the username
            while (!Commands.isInDatabase("password", encryptPassword(Password, splitPassSalt[1])))
            {
                Console.WriteLine("Wrong password! Try again.");
                SecureString pass2 = Commands.maskInputString();
                Password = new System.Net.NetworkCredential(string.Empty, pass2).Password;
                Console.WriteLine();
            }

            //Gets data from the Database
            string messages = Commands.getData("Users", "username", "messages", username);

            string type = Commands.getData("Users", "username", "type", username);

            string cars = Commands.getData("Users", "username", "cars", username);

            string gender = Commands.getData("Users", "username", "gender", username);

            //Gets how many unread messages the user has
            string[] output = messages.Split('\n');
            Console.WriteLine($"You have {output.GetLength(0) - 1} unread messages!");

            //Gets how many views the user's cars have
            string[] carIds = cars.Split(',');
            for (int i = 1; i < carIds.GetLength(0); i++)
            {
                Console.WriteLine($"{carIds[i]} : {Commands.getData("Cars", "carId", "views", carIds[i])}");
            }

            if (type == "regular user")
            {
                IUser user = new RegularUser
                {
                    username = username,
                    password = Password,
                    cars     = cars,
                    messages = messages,
                    gender   = gender,
                    type     = type
                };
                return(user);
            }
            else if (type == "dealer")
            {
                IUser user = new Dealer
                {
                    username = username,
                    password = Password,
                    cars     = cars,
                    messages = messages,
                    gender   = gender,
                    type     = type
                };
                return(user);
            }
            else
            {
                IAdministrator user = new Administrator
                {
                    username = username,
                    password = Password,
                    messages = messages,
                    gender   = gender,
                    type     = type
                };

                return(user);
            }
        }