Exemple #1
0
        public void SignUp(string username, string password)
        {
            if (ChackUsername(username))
            {
                UsersBase client = new UsersBase();

                if (head == null)
                {
                    head = client;
                    tail = client;
                }
                else
                {
                    tail.NextUser = client;
                    tail          = client;
                }

                SetUsrname_Password(client, username, password);
                CountUsers++;
                Console.WriteLine("Account successfully created: Username: "******"An account with that username already exists: Username: " + username);
            }
        }
Exemple #2
0
        public UsersBase LogIn(string username, string password)
        {
            UsersBase current = head;

            while (current != null)
            {
                if (username == current.Username && current.ChackPassword(password))
                {
                    return(current);
                }
                current = current.NextUser;
            }
            return(null);
        }
Exemple #3
0
        private bool ChackUsername(string username)
        {
            UsersBase current = head;

            while (current != null)
            {
                if (username == current.Username)
                {
                    return(false);
                }
                current = current.NextUser;
            }

            return(true);
        }
Exemple #4
0
        public void InfoAUser(int id) // overloading
        {
            UsersBase currnet = head;

            while (currnet != null)
            {
                if (currnet.ID == id)
                {
                    InfoAUser(currnet, id);
                    return;
                }
                currnet = currnet.NextUser;
            }
            Console.WriteLine("Wrong ID");
        }
Exemple #5
0
        public void Info()
        {
            UsersBase users = head;

            Console.WriteLine($"Users' count: {CountUsers}\n");
            for (int i = 0; i < CountUsers; i++)
            {
                Console.WriteLine($"User ID: {users.ID}");
                Console.WriteLine($"Username: {users.Username}");
                Console.WriteLine("Password: ******");
                Console.WriteLine(new string('-', 15));

                users = users.NextUser;
            }
        }
Exemple #6
0
        public void InfoAUser(string username) // overloading
        {
            UsersBase currnet = head;

            while (currnet != null)
            {
                if (currnet.Username == username)
                {
                    InfoAUser(currnet, username);
                    return;
                }
                currnet = currnet.NextUser;
            }
            Console.WriteLine("Wrong username");
        }
        public void Info()
        {
            UsersBase users = head;

            Console.WriteLine("\nUsers all info!");
            Console.WriteLine($"\nUsers' count: {CountUsers}\n");

            while (users != null)
            {
                Console.WriteLine($"User ID: {users.ID}");
                Console.WriteLine($"Username: {users.Username}");
                Console.WriteLine($"Password: {users.password}");
                Console.WriteLine(new string('-', 15));
                users = users.NextUser;
            }
        }
Exemple #8
0
        public override bool Remove()
        {
            UsersBase pre = null;
            UsersBase cur = head;

            Console.Write("Username: "******"Password: ");
            string password = Console.ReadLine();

            while (cur != null)
            {
                if (username == cur.Username && cur.ChackPassword(password))
                {
                    if (pre != null)
                    {
                        pre.NextUser = cur.NextUser;

                        if (cur.NextUser == null)
                        {
                            tail = pre;
                        }
                    }
                    else
                    {
                        head = head.NextUser;
                        if (head.NextUser == null)
                        {
                            tail = null;
                        }
                    }
                    CountUsers--;
                    return(true);
                }
                pre = cur;
                cur = cur.NextUser;
            }
            return(false);
        }
        static void Main(string[] args)
        {
            User user = new User();

            user.SignUp("Tigran", "123456");
            user.SignUp("Tigran", "123gh56");
            user.SignUp("Vahram", "787979");
            user.SignUp("Erik", "224716");
            user.SignUp("Robert", "174865");
            user.SignUp("Karlen", "175462");

            Console.Write("\nLog in\nUsername: "******"Password: "******"Successfully log in");
                Console.WriteLine("Your ID: " + userLogin.ID);
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Wrong username or password");
            }

            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine(new string('-', 15));

            UsersBase usersBase = user; // UpCast

            usersBase.Info();


            Console.WriteLine("Please input username and password for remove ");
            if (user.Remove()) // override method
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("Successfully removed.");
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Wrong username or password!!!");
            }
            Console.ForegroundColor = ConsoleColor.White;

            Console.WriteLine("\n" + new string('-', 15));

            user = usersBase as User; // DownCast
            user.Info();


            user.InfoAUser("Vahram");
            Console.WriteLine(new string('-', 15));
            user.InfoAUser(123546);

            Console.ReadKey();
        }
 protected void InfoAUser(UsersBase position, int id)
 {
     Console.WriteLine("{0}, info with this ID", id);
     Console.WriteLine($"{id} Username: {position.Username}");
     Console.WriteLine($"{id} Password: {position.password}");
 }
 protected void InfoAUser(UsersBase position, string username)
 {
     Console.WriteLine("{0}'s info", username);
     Console.WriteLine($"{username} ID: {position.ID}");
     Console.WriteLine($"{username} Password: {position.password}");
 }
 public void SetUsrname_Password(UsersBase client, string username, string password)
 {
     client.Username = username;
     client.password = password;
 }