【发布时间】:2015-06-23 01:24:22
【问题描述】:
所以我正在使用统一引擎在手机游戏中制作我的自定义高分板。
我设置了我的 mysql 数据库,并从商店购买了高分资产,它可以工作,但只能使用英文用户名。所以基本上它将用户名,分数发送到 .php 脚本。
但我希望该脚本也可以接收韩语字符作为用户的昵称。我的用户也将使用韩文字符作为昵称,而不仅仅是英文字符。
我怎样才能做到这一点?
这里是代码。
------------------(统一端的 Highscore.cs)
WWWForm rsFm = new WWWForm();
rsFm.AddField("name",name);
// at here name field, I want to receive korean characters as well.
rsFm.AddField("tables",tables);
rsFm.AddField("hash",GetHash(name));
WWW rs = new WWW(registerUserURL,rsFm);
yield return rs;
........
string GetHash(string usedString){ //Create a Hash to send to server
MD5 md5 = MD5.Create();
byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey);
byte[] hash = md5.ComputeHash(bytes);
StringBuilder sb = new StringBuilder();
for(int i = 0; i < hash.Length; i++){
sb.Append(hash[i].ToString("x2"));
}
return sb.ToString();
}
注册用户.php
<?php
include('ServerConnect.php');
$connection = Connect();//Attempt to Connect to MYSQL Server & DataBase
//Get variables from unity
$name = $_POST['name'];
$date = strtotime(date("Y-m-d"));
$tables = $_POST['tables'];
//Security Check
$hash = $_POST['hash'];
if(CheckKey($hash,$name) == 'fail'){ //Check if hash is valid
echo 'Security Failure'; exit;
}
ServerConnect.php
function CheckKey($hash,$name){ //Check weather Md5 hash matches
global $secretKey;
$checkHash = md5($name.$secretKey);
if(strcmp($checkHash,$hash) == 0){
return 'pass'; //hash matches
}else{
return 'fail'; //hash failed
}
}
当我输入韩语字符并发送时,控制台结果在上面的代码中显示“安全失败”。
【问题讨论】:
-
也许您应该在尝试散列之前对插入的值进行编码?
-
byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey);。您的 C# 代码使用了错误的编码。 -
也许您应该将分数或等价物与名称和盐一起散列,创建一个正确的校验和?如果您只对名称进行散列,用户可以嗅探名称/散列并使用不同的分数集发布。
-
@OfirBaruch 怎么办?
-
@Phylogenesis 那我应该怎么修改呢?