This is indeed a bit off-topic for AMXX, however you almost got it, you just need to salt out the password with your salt string. The PHP equivalent would be:
PHP Code:
<?php
define('SALT', '8c4f4370c53e0c1e1ae9acd577dddbed');
function hashPass($password) {
$passWithSalt = $password . SALT;
return md5($passWithSalt);
}
$password = "your_password_from_login";
$hashedPassword = hashPass($password);
echo $hashedPassword;
?>
In principle,
MD5 hashing should produce the same result regardless of the programming language or library, provided the same input is given (salt/pass). To make sure that they are indeed producing the same result, just debug it in both languages:
PHP Code:
<?php
echo md5("test");
?>
And in AMXX something like this:
PHP Code:
stock convert_password()
{
new pass_test[34];
new converted_password[34];
formatex(pass_test, charsmax(pass_test), "test");
md5(pass_salt, converted_password);
return converted_password
}
server_print("%s", convert_password());
//(You can't directly copy paste and use this, make it a command or something, and then execute the command)
These should return both in PHP and AMXX:
098f6bcd4621d373cade4e832627b4f6
If not, you can also try the hash_string native:
https://www.amxmodx.org/api/amxmodx/hash_string
PHP Code:
//Example:
hash_string("test", Hash_Md5, output, charsmax(output));
However, you should note that
MD5 is not considered the most secure thing out there.
Also looking at your PHP code:
PHP Code:
header("Location: dashboard.php");
Just redirecting to 'dashboard.php' without session handling doesn't mean the user is kept logged in, so I'm assuming that piece of code was just an example.
There are some other more secure hash alternatives you can use with the
hash_string native from AMXX that also work with PHP. From these:
Hash_Crc32 Provides CRC32 hashing
Hash_Md5 Provides MD5 hashing
Hash_Sha1 Provides SHA1 hashing
Hash_Sha256 Provides SHA256 hashing
Hash_Sha3_224 Provides SHA3 224 bit hashing
Hash_Sha3_256 Provides SHA3 256 bit hashing
Hash_Sha3_384 Provides SHA3 384 bit hashing
Hash_Sha3_512 Provides SHA3 512 bit hashing
Hash_Keccak_224 Provides Keccak 224 bit hashing
Hash_Keccak_256 Provides Keccak 256 bit hashing
Hash_Keccak_384 Provides Keccak 384 bit hashing
Hash_Keccak_512 Provides Keccak 512 bit hashing
Hash_Sha3_512 and
Hash_Keccak_512 being the most secure due to having the longest bit length (512 bits), and being more robust. The older algorithms like
MD5,
SHA1, and some others, while still used are not as secure as the
SHA-3 and
Keccak options. Specifically,
MD5 and
SHA1 have vulnerabilities that have been exploited.
Quote:
How do I Encryption is the process of converting password for PHP?
|
Hashing and
encryption actually mean different things, though they might sound like the same. Hashing transforms data into a fixed-size value, typically for verification purposes and is irreversible, while encryption transforms data into another format for confidentiality and can be reversed with the correct key.
You can post questions like this in the #webdev channel in Alliedmodders Discord:
https://discord.com/invite/HUc67zN
__________________