コード例 #1
0
        private static string AskToLoginOrRegister(string input)
        {
            UserDatabase userDatabase = new UserDatabase();
            User         user         = new User();

            while (true)
            {
                if (input == "1")
                {
                    Console.WriteLine("\nPlease enter your name and password: \n");

                    user.Name     = Console.ReadLine();
                    user.Password = Console.ReadLine();

                    if (!IsPasswordValid(user.Password))
                    {
                        Console.WriteLine($"\n{user.Password} not found. Try again");
                        user.Password = Console.ReadLine();
                    }

                    string data = $"{user.Name}#{user.Password}";

                    var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "database.txt";

                    File.AppendAllText(path, data);

                    userDatabase.SearchDuplicatesOrAdd(user);
                }
                else if (input == "2")
                {
                    Console.WriteLine("\nPlease enter your name and password: \n");
                    user.Name     = Console.ReadLine();
                    user.Password = Console.ReadLine();

                    userDatabase.SearchForNameAndPassword(user);
                    break;
                }
            }

            return(Console.ReadLine());
        }
コード例 #2
0
        static void Main(string[] args)
        {
            //Task 1
            #region task 1
            //Console.WriteLine("Please enter your age:\n");
            //int age = Convert.ToInt32(Console.ReadLine());

            //if(age < 18)
            //{
            //    Console.WriteLine("\nYou are not allowed to drink alcohol and drive a vehicle.");
            //}
            //else if(age > 18 && age < 20)
            //{
            //    Console.WriteLine("\nYou are not allowed to drink alcohol but you can drive a vehicle.");
            //}
            //else
            //{
            //    Console.WriteLine("\nYou are allowed to drink alcohol and drive a vehicle.");
            //}
            #endregion

            //Task 2
            #region task2

            //Console.WriteLine("Please enter 4 numbers:\nAfter every number press ENTER.");
            //int number1 = Convert.ToInt32(Console.ReadLine());
            //int number2 = Convert.ToInt32(Console.ReadLine());
            //int number3 = Convert.ToInt32(Console.ReadLine());
            //int number4 = Convert.ToInt32(Console.ReadLine());

            //if(number1 > 0 && number2 > 0 && number3 > 0 && number4 > 0)
            //{
            //    Console.WriteLine("All numbers are bigger than 0\n");

            //    int sum = number1 + number2 + number3 + number4;
            //    int difference = number1 - number2 - number3 - number4;
            //    int product = number1 * number2 * number3 * number4;
            //    float quotient = number1 / number2 / number3 / number4;

            //    Console.WriteLine($"\nALL VALUES WILL BE HEAVILY ROUNDED!\nSum: {sum}; Diffrence: {difference}; Product: {product}, Quotient: {quotient}");
            //}
            //else
            //{
            //    Console.WriteLine("\nSome number is negative");
            //}
            #endregion

            //Task 3
            #region task3

            //Console.WriteLine("Please enter a number.\nNumber 0 will end the loop and display all numbers.");
            //List<int> allNumbers = new List<int>();

            //while(true)
            //{
            //    int num = Convert.ToInt32(Console.ReadLine());

            //    allNumbers.Add(num);

            //    if (num == 0)
            //    {
            //        allNumbers.Remove(0);

            //        foreach (int numb in allNumbers)
            //        {
            //            Console.WriteLine($"Your number: {numb}");
            //        }
            //        break;
            //    }
            //}
            #endregion

            //Task 4
            #region task4

            //Console.WriteLine("Please enter some words or numbers");
            //WordsDatabase wordsDatabase = new WordsDatabase();

            //while (true)
            //{
            //    string word = Console.ReadLine();
            //    wordsDatabase.SearchForDuplicatesOrAdd(word);
            //}
            #endregion

            //Task 5.1_unfinished
            #region task5.1_unfinished
            //string input = AskToMakeAChoice();

            //if (!IsChoiceValid(input))
            //{
            //    Console.WriteLine($"\n{input} not found");
            //    return;
            //}

            //AskToLoginOrRegister(input);

            #endregion

            //Task 5.2_messy but working.
            #region task5.2_messyButWorking

            Console.WriteLine("Your are not registered. Please enter your username and password: \n");

            User         user         = new User();
            UserDatabase userDatabase = new UserDatabase();

            user.Name     = Console.ReadLine();
            user.Password = Console.ReadLine();

            if (!IsPasswordValid(user.Password))
            {
                Console.WriteLine($"\n{user.Password} not found. Try again");
                user.Password = Console.ReadLine();
            }

            userDatabase.SearchDuplicatesOrAdd(user);

            Console.WriteLine("Now login. Enter your username and password: \n");

            user.Name     = Console.ReadLine();
            user.Password = Console.ReadLine();

            userDatabase.SearchForNameAndPassword(user);
            #endregion

            Console.ReadLine();
        }