//LOGIN private bool action_login() { //init user id to blank UserID = ""; string temp = ""; //init number of tries to 0 int numtries = 0; //Loop until user id is not blank while (UserID == "") { //prompt for user id chatserver.Write(client.GetStream(), AuthenticationProtocolValues.USERID_PROMPT); temp = chatserver.Read(client.GetStream()); //check if user is registered //allow up to 3 tries if (!IsRegisteredUser(temp)) { chatserver.Write(client.GetStream(), AuthenticationProtocolValues.USER_NOT_REGISTERED_MSG); if (++numtries >= 3) { return(false); } continue; } else { UserID = temp; //assign valid user id } } //init to blank Password = ""; //init number of tries to 0 numtries = 0; //Loop until password is not blank while (Password == "") { //prompt for password chatserver.Write(client.GetStream(), AuthenticationProtocolValues.PASSWORD_PROMPT); temp = chatserver.Read(client.GetStream()); //check if password is correct if (!IsUserPassword(UserID, temp)) { if (++numtries >= 3) { return(false); } continue; } else { Password = temp; //OK password is assigned } } //Check if user already has a active connection if (chatserver.ClientConnections[UserID.ToUpper()] != null) { chatserver.Write(client.GetStream(), AuthenticationProtocolValues.USER_ALREADY_LOGGED_IN); return(false); } return(true); }