我的 XNA 游戏需要通过WebRequest
一个 PHP 页面连接到我的网站,该页面检查用户的数据库并检查密码是否正确。
我已经有一个登录脚本,它将返回诸如“成功”或“失败”之类的消息,显然这是暂时的,出于安全原因需要改进,它很容易被伪造。
C# 登录请求
//Create the POST data
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = "username=" + user + "&pass=" + pass;
byte[] data = encoding.GetBytes(postData);
//Make a request
WebRequest request = WebRequest.Create("http://example.com/login.php");
request.Method = "POST"; //We are posting the info
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
//Open a stream, write into, then send it
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
//Get response
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
//Make a new stream, We will read from this
StreamReader sr = new StreamReader(stream);
string responseString = sr.ReadToEnd();
//TODO: If the responseString says the client if authenticated, procede, if not, display error to user (Invalid password, etc)
而 PHP 脚本只是查找用户并比较提交的密码(所有这些都与 Joomla 站点数据库集成,因此用户拥有站点和游戏帐户)。
现在,我的 PHP 脚本如何发回可靠的身份验证方式,并提供某种令牌/ID,所以当我想提交例如高分时,它知道它来自该用户,并且是不是被伪造的吗?