SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 19/02/2012, 04:29 PM   #1
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 3,133
Reputation: 645
Default Hash.inc ─ Hash value generator using PHP

Introduction

This include is an implementation of the PHP function hash. It provides a function to generate hash a value using HTTP with a simple piece of PHP code which you can see below.

Functions

Let's say, it has only one function (since it's not really a function as it works with different steps to generate the hash value):
pawn Code:
/*
    const e_Algorithms: iAlgorithm  The (name of the) algorithm your want to use
    const iIdx                      The index of the process (perhaps it could be playerid for register/login systems)
    szText[]                        The piece of text/string you want to hash
*/

stock Hash(const e_Algorithms: iAlgorithm, const iIdx, szText[]);

Callback(s):
pawn Code:
forward OnHashUpdate(const iIdx, szHash[]);

Here's a list of e_Algorithms:
pawn Code:
enum e_Algorithms {
    MD2,            MD4,            MD5,
    SHA1,           SHA224,         SHA256,         SHA384,         SHA512,
    RIPEMD128,      RIPEMD160,      RIPEMD256,      RIPEMD320,
    WHIRLPOOL,
    TIGER128_3,     TIGER160_3,     TIGER192_3,
    TIGER128_4,     TIGER160_4,     TIGER192_4,
    SNEFRU,         SNEFRU256,
    GOST,
    ADLER32,
    CRC32,          CRC32B,
    SALSA10,        SALSA20,
    HAVAL128_3,     HAVAL160_3,     HAVAL192_3,     HAVAL224_3,     HAVAL256_3,
    HAVAL128_4,     HAVAL160_4,     HAVAL192_4,     HAVAL224_4,     HAVAL256_4,
    HAVAL128_5,     HAVAL160_5,     HAVAL192_5,     HAVAL224_5,     HAVAL256_5
};

And here are the defines:
pawn Code:
#if !defined MAX_HTTP_SIZE
    #define MAX_HTTP_SIZE (1024)
#endif

#if !defined HASH_SERVER
    #define HASH_SERVER "ryder.com.nu/hash.php"
#endif
If these are set before the include, your settings will be applied.

PHP Code

Currently this include is using my free hosted website so a small delay in retrieving the result is quite possible. I recommend you to use your own server for no delays. If you're planning to do that just save the following code as hash.php, upload it to your FTP and don't forget to change ryder.com.nu/
PHP Code:
<?php
    
echo(hash($_POST["algo"], $_POST["data"]));
?>
Examples

Here's a quick example usage of Whirlpool and MD5:
pawn Code:
Hash(MD5, 10000,
    "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."
);
Hash(WHIRLPOOL, 10001,
    "The quick brown fox jumps over the lazy dog"
);

Your hash value be will generated under this callback:
pawn Code:
public OnHashUpdate(const iIdx, szHash[]) {
    switch(iIdx) {
        case 10000: {
            printf("MD5: %s", szHash);
        }
        case 10001: {
            printf("Whirlpool: %s", szHash);
        }
    }
}
will print us:
pawn Code:
MD5: fa5c89f3c88b81bfd5e821b0316569af
Whirlpool: b97de512e91e3828b40d2b0fdce9ceb3c4a71f9bea8d88e75c4fa854df36725fd2b52eb6544edcacd6f8beddfea403cb55ae31f03ad62a5ef54e42ee82c3fb35
This is analog for the rest of the hash algorithms. You can use iIdx as playerid for register/login systems perhaps.

Download

Hash.inc

Register/Login System (Example)

Register/Login System Example using Hash.inc

Changelog
  • 19/02/2011:
    • Initial release
  • 23/02/2011 (Important update!):
    • Fixes:
      • Security issues regarding hash values in Apache logs (Thanks to Slice!).
      • PHP Code
    • Adds:
      • URL Encoding for string validating so hash values don't get messed up.
    • Notes:
      • Nothing has been changed about the syntax: after update, no need to change anything.
__________________

Sup?

Last edited by RyDeR`; 23/02/2012 at 06:26 PM.
RyDeR` is offline   Reply With Quote
Old 19/02/2012, 04:48 PM   #2
SuperMarioRol
High-roller
 
SuperMarioRol's Avatar
 
Join Date: Dec 2009
Location: Castellón, Comunidad Valenciana, España
Posts: 1,742
Reputation: 13
Default Respuesta: Hash.inc ─ Hash value generator using PHP

Very very great. +rep
__________________


¿Necesitas que tu servidor esté en la lista "Hosted"?
Mandame un MP o mail a david.soler.balado@gmail.com
SuperMarioRol is online now   Reply With Quote
Old 19/02/2012, 06:12 PM   #3
[XST]O_x
High-roller
 
[XST]O_x's Avatar
 
Join Date: Aug 2009
Posts: 1,992
Reputation: 79
Default Re: Hash.inc ─ Hash value generator using PHP

Amazing work mate!
[XST]O_x is offline   Reply With Quote
Old 19/02/2012, 06:33 PM   #4
royal_king
Gangsta
 
royal_king's Avatar
 
Join Date: Jul 2010
Location: Hyderabad, India (i think)
Posts: 634
Reputation: 38
Default Re: Hash.inc ─ Hash value generator using PHP

Amazing dude! Really helpful
__________________
Freelancing Web Developer & Designer
Contact Info:
Skype - viswanath608
royal_king is offline   Reply With Quote
Old 20/02/2012, 12:16 AM   #5
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 3,133
Reputation: 645
Default Re: Hash.inc ─ Hash value generator using PHP

Thanks! Let me know if you more examples for other cases, not mentioned in the first post.
__________________

Sup?
RyDeR` is offline   Reply With Quote
Old 20/02/2012, 12:38 PM   #6
Modrlicc
Little Clucker
 
Join Date: Dec 2009
Posts: 29
Reputation: 12
Default Re: Hash.inc ─ Hash value generator using PHP

Will become very handy! Thanks for this.
Modrlicc is offline   Reply With Quote
Old 20/02/2012, 01:24 PM   #7
Niko_boy
High-roller
 
Niko_boy's Avatar
 
Join Date: Aug 2010
Location: Somewhere i belong
Posts: 1,428
Reputation: 137
Default Re: Hash.inc ─ Hash value generator using PHP

This one is awesome now i can use it to hash , so it will be like -1 plugin from my server.cfg [whirlpool]
__________________
$$$ If anyone want to get any of these:
  • DM/TDM/Freeroam/Stunt server, filterscripts or Bug fixing.or some general mapping. Above all any of the logos and banners or signature sorta stuff aswell.at some cheap and worth-full prices.
can Contact me for more info or a deal.
•••[0.3x]LCS•Freeroam•DM•Stunts•Race•Parkour•••AutoArena [0.3z][No SkinShot][sixtytiger.com]Want a decent Attack Defend Gamemode?
176.31.120.76:7777176.31.229.148:7830Get This! Attack-Defend(v2.3.1)
Niko_boy is offline   Reply With Quote
Old 20/02/2012, 03:38 PM   #8
xkirill
High-roller
 
xkirill's Avatar
 
Join Date: May 2011
Location: In a box infront of your house stealing your WiFi
Posts: 2,645
Reputation: 312
Default Re: Hash.inc ─ Hash value generator using PHP

Another good release by RyDeR

P.S. what is this:"e_Algorithms" ?
__________________
KrustyGames
Kaperstone.ru
Quote:
Originally Posted by Mellnik View Post
Looks like someone's trying to attack your unprotected server :O.
xkirill is offline   Reply With Quote
Old 20/02/2012, 04:20 PM   #9
iZN
High-roller
 
Join Date: Jun 2010
Posts: 2,279
Reputation: 413
Default Re: Hash.inc ─ Hash value generator using PHP

Another great release by RyDeR, thank you!
__________________
Steam | Real Stunt World | Impulse99


- Scripting Services - Signature by Epixha -
iZN is online now   Reply With Quote
Old 20/02/2012, 05:23 PM   #10
RyDeR`
High-roller
 
RyDeR`'s Avatar
 
Join Date: Feb 2009
Location: Belgium
Posts: 3,133
Reputation: 645
Default Re: Hash.inc ─ Hash value generator using PHP

Thanks!

Quote:
Originally Posted by xkirill View Post
Another good release by RyDeR

P.S. what is this:"e_Algorithms" ?
Just an enumerator containing all algorithm names (better indexes).
__________________

Sup?
RyDeR` is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
adler32 PAWN hash does not match PHP hash Chris. Scripting Help 6 21/02/2012 05:57 PM
MD5 Hash = ? Micheal_ Help Archive 2 09/07/2011 06:59 PM
Hash help Carrot Help Archive 0 10/04/2011 10:58 AM
Hash ScottCFR Help Archive 2 20/07/2010 12:13 PM
Hash godknightx Help Archive 1 06/03/2010 09:32 AM


All times are GMT. The time now is 09:59 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.