Пример #1
0
        public void HandleObject_Login(Socket socket, MessageLogin messageLogin)
        {
            MessageBoxResponse    response;
            Account               user_account;
            IEnumerable <Account> accounts = CSVHandler.GetAccounts();
            bool logged_in = false;

            // Compares the username and password against all of those in the CSV
            foreach (Account account in accounts)
            {
                // When there is a match, set login flag and break loop
                if (account.Username == messageLogin.Username && account.Password == messageLogin.Password)
                {
                    logged_in    = true;
                    user_account = account;
                }
            }

            // Successful login
            if (logged_in)
            {
                response = new MessageBoxResponse($"Successful login. Welcome, {messageLogin.Username}!" +
                                                  "\nPassage to the messaging screen is currently unimplemented", "Login attempt");
                PrintMessage($"{socket.RemoteEndPoint} logged in as '{messageLogin.Username}'");
            }
            // Unsuccessful login
            else
            {
                response = new MessageBoxResponse($"Unsuccessful login, try again", "Login attempt");
                PrintMessage($"{socket.RemoteEndPoint} attempted login to '{messageLogin.Username}'");
            }

            // Sends the MessageBoxResponse to client
            SendObject(response, socket);
        }
Пример #2
0
        private string Command_LOGIN(string[] message)
        {
            string response = "InvalidLogin: Unknown error";

            // if not: "Login: [username] [password]"
            if (message.Length != 3)
            {
                response = "InvalidLogin: Invalid number of credentials supplied";
            }
            else
            {
                string username  = message[1];
                string password  = message[2];
                bool   logged_in = false;

                IEnumerable <Account> accounts = CSVHandler.GetAccounts();

                //Compares the username and password against all of those in the CSV
                foreach (Account account in accounts)
                {
                    PrintMessage($"{account.Username},{account.Password},{account.PublicKey},{account.PrivateKey}");

                    // When there is a match, set login flag and break loop
                    if (account.Username == username && account.Password == password)
                    {
                        response  = $"ValidLogin: Welcome {username}!";
                        logged_in = true;
                    }
                }

                // When the supplied credentials don't match any of those in the CSV
                if (!logged_in)
                {
                    response = "InvalidLogin: User matching your credentials doesn't exist";
                }
            }

            return(response);
        }