/// <summary> /// Processing login request /// </summary> /// <param name="requestSplit">Format: LOGIN_username_password</param> /// <returns>Response message for client</returns> public string ProcessLoginRequest(string[] requestSplit, Client client) { //TODO: What if this user is already logged in ? (On different computer?) if (requestSplit.Length != 3) return null; string username = requestSplit[1]; string password = AsymmetricEncryption.DecryptText(requestSplit[2], client.GetKeySize(), client.GetPrivateKey()); List<string> userSelect = mainDatabase.SelectUsers(username, password); if (userSelect.Count == 1) { //We have to update status of our client to 'connected' SwitchClientIntoLoginState(client); return "LOGIN_OK"; } return "LOGIN_NOK"; }
/// <summary> /// Register new user into database /// </summary> /// <param name="requestSplit">Format: REGISTER_username_password</param> /// <returns>Response message for client</returns> public string ProcessRegisterRequest(string[] requestSplit, Client client) { if (requestSplit.Length != 3) return null; string username = requestSplit[1]; string password = AsymmetricEncryption.DecryptText(requestSplit[2], client.GetKeySize(), client.GetPrivateKey()); User user = new User(username, password, "mailadress"); bool insertSussesful = mainDatabase.RegisterUser(user); if (insertSussesful) { return "REGISTRATION_OK"; } else return "REGISTRATION_NOK"; }