Simple Score Submission Security

keys!

If you’ve made a Flash game with a PHP high score table without any security before, you’ve probably found some unpossible scores sitting on top of your chart when you wake up one morning. Well, in this tutorial, we’ll see how to implement a simple encryption system that is relatively secure for Actionscript 3.0. It’s not perfectly secure, but it will fend off your usual score cheater. This tutorial also assumes that you know the basics of implementing a high score system in Flash and PHP. If you don’t, please check out this tutorial.

The basic concept of this method is to use MD5 to hash the submission data with a key. Then we send the data, along with the MD5 hash to the PHP script. The PHP script takes the data, and hashes it with the same key. If the two hashes match, then we know it’s legit.

First, let’s go over what to do on the Flash side of things. We will need an encryption API capable of MD5 for AS3, such as this encryption package by Geoffrey Williams. There are others which can be found by Googling, but this one is pretty simple to use.

Suppose we want to submit the player’s name and score, we construct a string of those values:

var playerData:String = playerName + playerScore;

Then we use the MD5 package to hash it with a key, which is a secret string that we make up. Assuming we are using the package shown above, the code would look something like this:

var key:String = "HASH_KEY";
var hashData:String = MD5.hex_hmac_md5(key, playerData);

After we have this, we just send both the playerData and hashData to our PHP score submission script using a POST method.

Over on the PHP script, we take the playerData, and run it through MD5 with the same secret key that we used in Flash. If the result matches the hashData that we received from Flash, then it’s a valid score submission. The operative PHP functions here are bin2hex and mhash.

$key = "HASH_KEY";
$result = bin2hex(mhash(MHASH_MD5, $playerData, $key));
if ($result == $hashData)
{
    //record submission
}

Thats all there is to this encryption method. You’ve probably noticed, but the one flaw to this method is that if the hacker has access to the Flash source, then he can find out the secret key and beat the system. Fortunately, as far as I know, there are no public AS3 decompilers yet. Should one appear, we’d have to use obfuscation to hide the key or use some sort of SWF encryption program such as Amayeta. Nonetheless this method should keep most casual cheaters off your back.

Tags: , , ,

31 Responses to “Simple Score Submission Security”

  1. andrew says:

    useful idea! however, just fyi – mhash is deprecated in the newest versions of PHP, there’s a new built-in hash library

    you’d actually want to use: hash(“md5″, $playerData, $key)

    - andrew

  2. Kriss Daniels says:

    Sorry but this doesn’t work, the general flash score hacker does it by tweaking internal flash variable numbers (ie their score) using simple memhack (think action replay) cheat software.

    So they probably wouldn’t even notice this…

    I use replays. Sounds complicated but isn’t that bad if you only check suspicious scores and do so on the client.

  3. John says:

    A bit late but it is actually the hash_hmac function that you would want to use e.g.

    hash_hmac(‘md5′, $playerData, $key);

  4. vv0lll says:

    But, what’s up if the hacker decompiles our Flash and they know how we encoded our data ?

  5. doogog says:

    Yes, if they decode your file, this method will be revealed.

  6. Unlimited Master Reseller says:

    I loved everything. Please keep posting tips regarding different scripts.

  7. Konsult says:

    What’s Happening i am new to this, I stumbled upon this I’ve discovered It positively useful and it has helped me out loads. I hope to give a contribution & assist other users like its helped me. Great job.

  8. rhythm flash games says:

    rhythm flash games…

    [...]Doogog.com » Blog Archive » Simple Score Submission Security[...]…

  9. Jfxzchyy says:

    very best job http://ofapolyykeg.blog.free.fr/ teen lily model Beautiful Heather. We love your new friend. Now if your husband would’ve done her from behind and unloaded right after you, now that’s acadamy award material!

  10. Xxxnisad says:

    What university do you go to? http://mobakefisu.de.tl nudist nude models I’d love to give her a facial every night. Gotta keep the woman happy! Don’t think I’d ever go out of town, tho…LOL!

  11. Chajsxma says:

    I stay at home and look after the children http://kiqedeteno.de.tl sarah model She’s hot and all but I can’t jerk off to this! I mean I could but it wouldn’t be as good as with porn.

  12. Qmndjxmy says:

    I’m about to run out of credit http://uesulajar.de.tl daddys little pussy I love how he finishes, he doesnt give a fuck if she cant take any more while hes cumming, she literally pukes his cock out, fuckin hot

  13. Dztlkhqz says:

    How would you like the money? http://dykusepebojic.de.tl porn little cuties
    Yes, she’s got a great pussy and nice tits, but couldn’t she find a cock to do the work, instead of abusing some dumb as a brick vibrator?

  14. site says:

    Wanted to drop a remark and let you know your Feed isnt working today. I tried adding it to my Google reader account and got absolutely nothing.

  15. here says:

    Can you email me with any hints & tips on how you made this blog look this cool , Id appreciate it!

  16. software free 24 says:

    I have read so many articles on the topic of the blogger lovers except
    this post is actually a nice paragraph, keep it up.

  17. Staci says:

    For most up-to-date information you have to pay a visit world-wide-web and on world-wide-web I
    found this website as a best site for latest updates.

  18. websites says:

    I approximating this post, enjoyed this one regards for putting up.

  19. Hdecwzwd says:

    I’m doing an internship

  20. http://tinyurl.com/marijenks47328 says:

    “Doogog.com

  21. Yljghjfc says:

    Languages jennaj
    id tap that

  22. Lhkoyerc says:

    I want to make a withdrawal bigboobsz
    LOL i can’t believe that got me off..

  23. Ioccrrya says:

    Jonny was here babblesex
    love this vid. Not in my face Motherf*cker

  24. Cody says:

    Could I order a new chequebook, please? naked lolita girls peeing number one, the girl is hot,nice and horny and a plus for her, she got a tight pussy but then again what kind of a boyfriend in his healthy mind would allow his girl to get banged by some other dude…!!!’it’s good what you did DFW, i would have come in her pussy,too..But did she get pregnant or was it just for the film?

  25. Gavin says:

    How do you know each other? young lolita rape pics Maybe this film will help pay for her brand-new shiny pussy!

  26. porn says:

    I’ve been browsing online greater than 3 hours nowadays, yet I never discovered any attention-grabbing article like yours. It’s lovely value enough for me. In my opinion, if all webmasters and bloggers made good content as you did, the net might be much more useful than ever before.

  27. evolv health says:

    Excellent post. I was checking continuously this weblog and I am impressed! Very helpful info specifically the closing part :) I handle such information much. I was seeking this certain information for a long time. Thanks and good luck.

  28. Christy says:

    I wanted to thank you for this excellent read!! I absolutely loved every bit
    of it. I’ve got you saved as a favorite to check out new things you post…

    Feel free to visit my page :: Christy

  29. asesores de ventas online says:

    Hello there, simply turned into alert to your weblog through Google, and found that it’s truly informative. I’m gonna be careful for brussels. I’ll be grateful if you happen to continue this in future. Many other people shall be benefited out of your writing. Cheers!

  30. dree porn says:

    I am extremely inspired along with your writing skills and also with the layout in your weblog. Is that this a paid subject or did you modify it your self? Either way keep up the nice high quality writing, it’s uncommon to see a nice weblog like this one today..

  31. phoenix arizona car insurance says:

    What i do not realize is actually how you’re not actually much more smartly-appreciated than you may be right now. You are very intelligent. You recognize therefore considerably with regards to this topic, made me in my opinion imagine it from so many numerous angles. Its like women and men don’t
    seem to be fascinated except it is one thing to accomplish with Lady gaga!
    Your own stuffs nice. All the time deal with it up!

Leave a Reply