Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Side · Jul 24, 2013 at 04:50 PM · tutorialphp

Help with modified php code from highscore tutorial

Resolved. I was using $vars['var_here'] instead of $vars['Var_here']

Working code

MySQL Table:

Name Password CharacterName (username) (md5-encrypted_password) (ingame_character_name)

Php code:

 <?php
   //Commented all debug code.
   $database = mysql_connect('mysql_host', 'mysql_user', 'mysql_password')
   or die('Could not connect: ' . mysql_error());
  
   mysql_select_db('mysql_database')
   or die('Could not select database');
  
   $gameversion = "1.0";
  
   $name = mysql_real_escape_string($_GET['name']);
   $password = mysql_real_escape_string($_GET['password']);
   $hash = mysql_real_escape_string($_GET['hash']);
  
   $Key = "secret_Key";
  
   //echo "Starting pull process.<span style='display: block;'></span>";
  
   if(md5($name . $password . $Key) == $hash)
   {
     //echo "Inside pull process. name, password, key = hash<span style='display: block;'></span>";
  
     $info = mysql_query("SELECT * FROM `users` WHERE Name='" . $name . "'")
     or die('Query failed: ' . mysql_error());
  
     //echo "Starting fetch process.<span style='display: block;'></span>";
  
     while($vars = mysql_fetch_array($info))
     {
       //echo "Inside fetch process, finding info = okay<span style='display: block;'></span>";
       //echo "Starting name check<span style='display: block;'></span>";
       //echo "DB Name: " . $vars['Name'] . "<span style='display: block;'></span>";
       if($name == $vars['Name'])
       {
         //echo "Name check passed.<span style='display: block;'></span>";
         //echo "Starting password check.<span style='display: block;'></span>";
         if($password == $vars['Password'])
         {
           //echo "Password check passed.<span style='display: block;'></span>";
           echo $vars['CharacterName'] . "\t" . $gameversion . "";
         }
         else{
           //echo "Password check failed.<span style='display: block;'></span>";
         }
       }
       else{
         //echo "Name check failed.<span style='display: block;'></span>";
         //echo "Received name: " . $name . "<span style='display: block;'></span>";
         //echo "DB name: " . $vars['Name'] . "<span style='display: block;'></span>";
       }
     }
   }
   else{
     echo "Process failed";
   }
 ?>

Javascript code:

 var username : String = "";
 var password : String = "";
 
 //GUI Stuff to get the username and password, tested, it works perfectly
 
 function LogIn(){
     infopost = WWW("http://server.testserver2013.herobo.com/server.php?name=" + username + "&password=" + Md5Sum(password) + "&hash=" + Md5Sum(username + Md5Sum(password) + "secret_Key"));
     yield infopost;
     if(infopost.error){
         Debug.LogError("Failure");
     }
     else{
         Debug.Log(infopost.text);
     }
 }
 
 //Just the md5 function from the wiki
 static function Md5Sum(strToEncrypt: String)
 {
     var encoding = System.Text.UTF8Encoding();
     var bytes = encoding.GetBytes(strToEncrypt);
  
     // encrypt bytes
     var md5 = System.Security.Cryptography.MD5CryptoServiceProvider();
     var hashBytes:byte[] = md5.ComputeHash(bytes);
  
     // Convert the encrypted bytes back to a string (base 16)
     var hashString = "";
  
     for (var i = 0; i < hashBytes.Length; i++)
     {
         hashString += System.Convert.ToString(hashBytes[i], 16).PadLeft(2, "0"[0]);
     }
  
     return hashString.PadLeft(32, "0"[0]);
 }
Comment
Add comment · Show 13
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dave-Carlile · Jul 24, 2013 at 05:56 PM 0
Share

What happens if you execute the PHP script from your browser? Do you see warnings or errors?

avatar image clunk47 · Jul 24, 2013 at 06:00 PM 0
Share

Thanks for giving out your 000Webhost username and password lol

avatar image Dave-Carlile · Jul 24, 2013 at 06:03 PM 0
Share

Edited out for you :). It would be a good idea to change it asap.

avatar image clunk47 · Jul 24, 2013 at 06:04 PM 0
Share

This is really a PHP question, there could very well be something wrong with your script in Unity. That would be a big help if you'd post the UNITY script you are using.

avatar image Dave-Carlile · Jul 24, 2013 at 06:08 PM 1
Share

Add some echo statements in various places - make sure everything is working as you expect. Echo out variable values and such, make sure they're the values you expect. Once you get that all working while running in a browser, then go back to integrating with Unity.

Show more comments

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by tw1st3d · Jul 26, 2013 at 03:30 PM

Please implement this for your PHP code. The spans are added because the form was removing my line breaks, so you can just replace them with br tags if you want.

 <?php
     $database = mysql_connect('xxxxx', 'xxxxx', 'xxxxx') 
         or die('Could not connect: ' . mysql_error());
         
     mysql_select_db('xxxxx') 
         or die('Could not select database');
         
     $gameversion = "1.0";
      
     $name = mysql_real_escape_string($_GET['name']);
     $password = mysql_real_escape_string($_GET['password']);
     $hash = mysql_real_escape_string($_GET['hash']);
      
     $Key = "Universe";
     
     echo "Starting pull process.<span style='display: block;'></span>";
     
     if(md5($name . $password . $Key) == $hash)
     {
         echo "Inside pull process. name, password, key = hash<span style='display: block;'></span>";
         
         $info = mysql_query("SELECT * FROM `users` WHERE name='" . $name . "'")
             or die('Query failed: ' . mysql_error());
          
         echo "Starting fetch process.<span style='display: block;'></span>";
         
         while($vars = mysql_fetch_array($info))
         {
             echo "Inside fetch process, finding info = okay<span style='display: block;'></span>";
             echo "Starting name check<span style='display: block;'></span>";
             if($name == $vars['name'])
             {
                 echo "Name check passed.<span style='display: block;'></span>";
                 echo "Starting password check.<span style='display: block;'></span>";
                 if($password == md5($vars['password']))
                 {
                     echo "Password check passed.<span style='display: block;'></span>";
                     echo $vars['CharacterName'] . "\t" . $gameversion . "";
                 }else{
                     echo "Password check failed.<span style='display: block;'></span>";
                 }
             }else{
                 echo "Name check failed.<span style='display: block;'></span>";
             }
         }
     }else{
         echo "Pull process failed.<span style='display: block;'></span>";
     }
 ?>
Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Side · Jul 26, 2013 at 07:54 PM 0
Share

With your code:

 Starting pull process.
 Inside pull process.
  name, password, key =
  hashStarting fetch process.
 Inside fetch process, finding info = okay
 Starting name check
 Name check failed.
avatar image Side · Jul 26, 2013 at 07:58 PM 0
Share

@tw1st3d Further testing. Similar problem as with bompi88's code, but this time php doesn't find any name on the database

 Received name: Dev2
 DB name:
avatar image tw1st3d · Jul 26, 2013 at 08:16 PM 0
Share

add

 echo $vars['name'];

RIGHT before

 if($name == $vars['name'])
avatar image Side · Jul 27, 2013 at 09:21 AM 1
Share

@tw1st3d Done, php outputs nothing. Changed all $vars['var_here'] to $vars['Var_here']. It works Such a stupid thing...

avatar image tw1st3d · Jul 27, 2013 at 03:40 PM 0
Share

That means your tables row name is capitalized. You can change that through your database manager.

avatar image
0

Answer by bompi88 · Jul 25, 2013 at 10:01 AM

This is somewhat what I would have done. It's neither perfect or tested, but maybe it helps somehow.

Updated:

    <?php
         
         $gameversion = "1.0";
         
         // Get input data
         $name = $_GET['name'];
         $password = $_GET['password'];
         $hash = $_GET['hash'];
         $Key = "Universe";
         
         if(md5($name . $password . $Key) == $hash){
             // Override default html content-type
             header("Content-Type: text/plain");
             
             // Connect to the DB
             $pdo = new PDO('mysql:host=localhost;dbname=myDB;charset=utf8', 'mySQLusername', 'mySQLpassword');
             $msql = $pdo->prepare('SELECT * FROM `users` WHERE name=:name');
             $msql->bindParam(':name', $name, PDO::PARAM_STR);
             $msql->execute();
      
             if ($msql->rowCount() > 0) {
      
                 $info = $msql->fetch(PDO::FETCH_ASSOC);
                 // If passwords in the database are hashed, as they should be.
                  if($password == $info['password']){
                       echo $info['CharacterName'] . "\t" . $gameversion . "\n";
                  } else {
                     echo "Hashed passwords don't match";
                 }
             } else {
                  echo "No entity with that name found in database, or something wrong with SQL statement.";
             }
         } else {
             echo "Something's wrong with either of the get inputs, which results in mismatch of the hashes.";
         }
     ?>
Comment
Add comment · Show 7 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Side · Jul 25, 2013 at 12:46 PM 0
Share

Helps, but now I'm getting just some Hosting24 analytics code

 <!-- Hosting24 Analytics Code -->
 <script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
 <!-- End Of Analytics Code -->
avatar image Side · Jul 25, 2013 at 12:48 PM 0
Share

Which surprise me because I have just pasted the correct host, user database and password to your php code and I haven't enabled any type of analytic or tracking feacture in the user panel

avatar image bompi88 · Jul 25, 2013 at 05:00 PM 0
Share

Ok, it's not writing out character name/game version etc? How to disable the analytics?

avatar image bompi88 · Jul 25, 2013 at 11:47 PM 0
Share

Updated my code, do you get one of those error messages I put in there?

avatar image bompi88 · Jul 25, 2013 at 11:59 PM 0
Share

Shouldn't variable 'name' inside:

    ... + "&hash=" + $$anonymous$$d5Sum(name + $$anonymous$$d5Sum(password) + "Universe")

in your JS be 'username'?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

Setting up Unity Steer 0 Answers

Put user list in 2d array 1 Answer

Unity 3 GD HotShot-Tutorial Problem with an C#-Array 1 Answer

How to Make a FPS without knowledge [BEGINNER] ! 5 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges