Raised This Month: $ Target: $400
 0% 

Hash Password verify in php


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
FonixPro20
Member
Join Date: Mar 2018
Old 09-30-2023 , 20:36   Hash Password verify in php
Reply With Quote #1

Why do hash password in Register System by m0skVi4a ;] did not work for login process in PHP?

How do I Encryption is the process of converting password for PHP?

PHP Code:
#define SALT "8c4f4370c53e0c1e1ae9acd577dddbed"
new check_pass[34];
 new 
password[33][34];

public 
HashPass(id)
{
 
password[id] = convert_password(check_pass)
}

stock convert_password(const password[])
{
    new 
pass_salt[64], converted_password[34];
    
formatex(pass_saltcharsmax(pass_salt), "%s%s"passwordSALT)
    
md5(pass_saltconverted_password)
    return 
converted_password

for php will be like?

PHP Code:

if ($result->num_rows == 1) {
    
$row $result->fetch_assoc();
  if ( 
md5($password) == $db_password) {
     
header("Location: dashboard.php");
     exit;

FonixPro20 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 09-30-2023 , 20:58   Re: Hash Password verify in php
Reply With Quote #2

Password's aren't encrypted (usually), they are hashed. PHP has built-in features for this, you should use them.

P.S. This is Scripting Help for AMX Mod X, you should ask somewhere more appropriate for PHP.
__________________
fysiks is offline
Rohanlogs
Senior Member
Join Date: Nov 2015
Old 10-02-2023 , 17:54   Re: Hash Password verify in php
Reply With Quote #3

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_testcharsmax(pass_test), "test");
    
md5(pass_saltconverted_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_Md5outputcharsmax(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
__________________
Rohanlogs is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 10-02-2023 , 22:04   Re: Hash Password verify in php
Reply With Quote #4

I didn't realize this request was about an actual plugin (because there was no "#include <amxmodx>" I just glossed over it and assume it was all PHP).

Quote:
Originally Posted by Rohanlogs View Post
You can post questions like this in the #webdev channel in Alliedmodders Discord:
https://discord.com/invite/HUc67zN
It's not really a good idea to divide the community into multiple places, IMO, it makes it harder for future users to search for the lessons learned in previous questions. I originally thought this was offtopic because I didn't realize it was asking about a plugin (as stated above).
__________________
fysiks is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 23:34.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode