dth2331 2014-04-26 10:31
浏览 86
已采纳

使用SQL进行Unity 3D安全身份验证

I'm developing an android application in unity 3d that will have network communications for user accounts updating said accounts as well as controlling everything on the back end of the app. I use the WWW class in unity to send info to the server. The backend is php and all the data is stored in a mysql database. How can I make a secure connection between the app and the backend without someone just simply getting the servers address and blocking it in their hosts file and feeding the app false info and going online with it.(as an example) I'm no security expert but I'm not sure what I need to look in too in order to create secure connections between server and client. Any help would be greatly apericiated. Thank you.

  • 写回答

1条回答 默认 最新

  • dphe5602 2014-04-26 20:55
    关注

    you just need to implement the www class

          void start()
          {
            StartCoroutine(retrieveHighscores()); //Start out by getting the current scores.
          }
    
        IEnumerator retrieveHighscores()
       {
    
        var form = new WWWForm(); // create a new form
    
    
        form.AddField("Nipun",name); // add the data you want to retrieve in the form fields
        var rawData = form.data;
        var headers = form.headers;  // here headers will be used to authenticate the credentials of the person trying to access
        headers["Authorization"]="Basic " + System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes("username:password"));
    
        WWW webRequest = new WWW("https://abc.com/test.php", rawData, headers); // 
    
        yield return webRequest;
        if (webRequest != null) {
      //here you have successfully got the response back from the server , here i am adding the whole response in a string and then splitting the string based on the format of the data i received.
                        string x = webRequest.text;
                        string[] lines = webRequest.text.Split(new string[] { System.Environment.NewLine }, System.StringSplitOptions.RemoveEmptyEntries); //Split the response by newlines.
            Debug.Log(x); // to check what you received
                        scores = new Dictionary<string, int>(); //Always reset our scores, as we just got new ones.
                        foreach (string line in lines) //Parse every line
                        {
                            // code here how you want to use the split up data you received
                        }
    
    
                }
        else
            Debug.Log("error");
    }
    

    }

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?