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");
    }
    

    }

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

报告相同问题?

悬赏问题

  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题