[Include] Hash.inc ─ Hash value generator using PHP
#1

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 Код:
/*
    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 Код:
forward OnHashUpdate(const iIdx, szHash[]);
Here's a list of e_Algorithms:
pawn Код:
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 Код:
#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 код:
<?php
    
echo(hash($_POST["algo"], $_POST["data"]));
?>
Examples

Here's a quick example usage of Whirlpool and MD5:
pawn Код:
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 Код:
public OnHashUpdate(const iIdx, szHash[]) {
    switch(iIdx) {
        case 10000: {
            printf("MD5: %s", szHash);
        }
        case 10001: {
            printf("Whirlpool: %s", szHash);
        }
    }
}
will print us:
pawn Код:
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.
Reply


Messages In This Thread
Hash.inc ─ Hash value generator using PHP - by RyDeR` - 19.02.2012, 15:29
Respuesta: Hash.inc ─ Hash value generator using PHP - by SuperMarioRol - 19.02.2012, 15:48
Re: Hash.inc ─ Hash value generator using PHP - by [XST]O_x - 19.02.2012, 17:12
Re: Hash.inc ─ Hash value generator using PHP - by royal_king - 19.02.2012, 17:33
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 19.02.2012, 23:16
Re: Hash.inc ─ Hash value generator using PHP - by Modrlicc - 20.02.2012, 11:38
Re: Hash.inc ─ Hash value generator using PHP - by Niko_boy - 20.02.2012, 12:24
Re: Hash.inc ─ Hash value generator using PHP - by Kaperstone - 20.02.2012, 14:38
Re: Hash.inc ─ Hash value generator using PHP - by iZN - 20.02.2012, 15:20
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 20.02.2012, 16:23
Respuesta: Hash.inc ─ Hash value generator using PHP - by [Nikk] - 20.02.2012, 17:10
Re: Respuesta: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 21.02.2012, 14:27
Re: Hash.inc ─ Hash value generator using PHP - by shitbird - 21.02.2012, 14:59
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 21.02.2012, 17:44
Re: Hash.inc ─ Hash value generator using PHP - by DRIFT_HUNTER - 21.02.2012, 17:48
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 21.02.2012, 17:51
Respuesta: Re: Respuesta: Hash.inc ─ Hash value generator using PHP - by [Nikk] - 21.02.2012, 17:54
Re: Hash.inc ─ Hash value generator using PHP - by shitbird - 21.02.2012, 18:17
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 21.02.2012, 21:27
Re: Hash.inc ─ Hash value generator using PHP - by Modrlicc - 22.02.2012, 17:00
Re: Hash.inc ─ Hash value generator using PHP - by Slash_ - 22.02.2012, 17:13
Re: Hash.inc ─ Hash value generator using PHP - by Slice - 22.02.2012, 17:40
Re: Hash.inc ─ Hash value generator using PHP - by RyDeR` - 23.02.2012, 17:30

Forum Jump:


Users browsing this thread: 2 Guest(s)