Beispiel #1
0
        public override void Execute(string param = null)
        {
            if (param == null)
            {
                Console.WriteLine("ip_address required");
                return;
            }

            var rnd = new Random();

            Console.Write("Connecting to {0}", param);
            for (int i = 0; i < rnd.Next(2, 8); i++)
            {
                Thread.Sleep(1000);
                Console.Write(".");
            }
            _currentDataBase = DataBase.GetDatabaseByIp(param);
            if (_currentDataBase == null)
            {
                Console.WriteLine("Failed to connect to {0}. Are you sure that IP is correct?", param);
                return;
            }

            Console.WriteLine("Connection succesfull");
            if (!Authenticate(_currentDataBase))
            {
                _currentUser     = null;
                _currentDataBase = null;
                Console.WriteLine("Authentication failed!");
                return;
            }
            if (_currentUser.IsLocked)
            {
                _currentUser     = null;
                _currentDataBase = null;
                Console.WriteLine("This user is locked! Contact database admin for more info");
                return;
            }
            Console.WriteLine("Welcome to {1}, {0}!", _currentUser.Login, _currentDataBase.Name);
            Console.WriteLine("Please enter your query bellow, or type exit to leave:");
            _queryLimit = rnd.Next(5, 10);
            while (HandleUserQueries())
            {
                ;
            }
            _currentDataBase = null;
            _currentUser     = null;
            Console.WriteLine("Goodbye!");
        }
Beispiel #2
0
        private bool Authenticate(DataBase db)
        {
            Console.Write("Login: "******"User {0} doesn't exist!", login);
                return(false);
            }

            Console.Write("Password: ");

            return(_currentUser.Password == Console.ReadLine());
        }