So I am making my custom highscore board in mobile game, using unity engine.
I setup my mysql database, and bought highscore asset from store, it works, but only with english user name. So basically it send user's name, score to .php script.
But I want that script also can receive korean characters as user's nickname. My users will use korean characters too as nickname not only english characters.
How can I achieve this?
Here are codes.
------------------(Highscore.cs at unity side)
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();
}
RegisterUser.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
}
}
When I input korean character and send, console Result says "Security Failure" at above code.
byte[] bytes = Encoding.ASCII.GetBytes(usedString+secretKey);
. Your C# code is using the wrong encoding.