PHP md5 () gives a different output, then MySQL md5

I am trying to configure a login system, but I cannot solve one problem: PHP gives me a different result using md5 (); than MySQL ...

For example, in PHP:

$password = md5("brickmasterj"); return $password; 

Returns:

 3aa7b18f304e2e2a088cfd197351cfa8 

But the MySQL equivalent gives me a shorter version:

 3aa7b18f304e2e2a08 

What is the problem? And how do I work with this when checking passwords?

+8
php mysql md5
source share
4 answers

I think the problem is the column length of your table, set the password field length to at least 32

+8
source share

MySQL in no way returns its length <32. If you make a simple query, for example SELECT md5('brickmasterj') , you will see. Now you are most likely pasting a value into a column that is not wide enough.

+2
source share

Is your database field 32 characters long? Are you writing to the database using mysql md5?

+2
source share

The size of the hash, if it is always fixed. In your case, the hash size is 128 bits. When converted to ascii string, it will be a 32 character string containing only hexadecimal digits. therefore, if you store a variable character, the length must be at least 32 Example: password varchar(32) should go in the mysql table, then you can call using php using select password from table where password =md5($password);

0
source share

All Articles