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
1
Question by DarkSlash · May 19, 2012 at 03:15 PM · mysqlphpsecurity

Protect the PHP file that connects to mySQL

I have a game that connects to a mysql database through a php file. I was wondering how to protect that file from being accessed from, for example, the browser?

In the file I require user id, gold and item. So I check if the userID exist, if the user has the gold that is has sent to the script, and if the item cost is lower or equal to the gold amount that it was sent. If that things happens, the item is sold to the user and the 100 gold coins are deducted from the user gold.

But, is someone "discovers" the path and the variables name, can do something like mydomain/script.php?userid=4&gold=100⁢em=239 and if the user 4 exists, it has 100 of gold and the item 239 costs 100 o less... the item wild be sold to that user and 100 of gold will be deducted...

So how do you deal with that? I though of also giving a secret code, for example mydomain/script.php?userid=4&gold=100⁢em=239&secretcode=kdsSDfsdfSDF and then check in the script.php if that code is correct, its like a pre-shared key, but it seems to easy to hack.

What would you do?

Comment
Add comment
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

2 Replies

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

Answer by flaminghairball · May 19, 2012 at 03:27 PM

I'm far from a security or PHP expert(scratch that - I'm far from a security or PHP newbie), but I believe that the server side highscores script uses an MD5 hash for exactly this purpose: http://unifycommunity.com/wiki/index.php?title=Server_Side_Highscores

Comment
Add comment · Show 1 · 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 DarkSlash · May 19, 2012 at 05:00 PM 0
Share

Oh it was something like that... a secret code + some data to prevent the guessing of the word... like that! thanks! :)

avatar image
0

Answer by dineshrajpurohit · Jun 20, 2012 at 08:01 AM

First. It is very difficult to retrieve your file path from the Unity web application and if someone succeeds, I would suggest using MD5 with salt. Salt makes your code more secured. Here is an example.

  public function createHashedData($data){
     $salt = "SoMeWiErDsTrInGwItHnUmBeRs123455"
     $context = hash_init("md5", HASH_HMAC, $salt);
     hash_update($context, $data);
     return hash_final($context);
 }

But in your case all this will not do any good if someone comes across your link he can send the data anyways. The best way to do is create a session whenever a user logs into your game and store it in database and delete the session once the person logs off.

By storing the session you can always check the session with the user and if exists deduct the money and stuff.

Benefit: So if someone come across the link he wont be able to do anything since he does not have session data with him and the link will be of no use to him.

I hope this will help.

Dins

Comment
Add comment · 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

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

6 People are following this question.

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

Related Questions

Unity to PHP/MySQL: password and username security 1 Answer

Call to PHP security (transmission security)? 0 Answers

How to make a highscore database for unity? 1 Answer

Connecting to a MySQL database in a Unity dedicated server without PHP or any other middleman? 1 Answer

Load entire table from MySQL 1 Answer


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