I
I
IsaevDev2015-09-03 03:50:07
PHP
IsaevDev, 2015-09-03 03:50:07

Why does the sha256 value change after writing to the database?

Hashing

$hash = hash( 'sha256', $newlogin . $newpass . $salt );

write to the database
"INSERT INTO `admin` ( `login`, `passhash`  ) VALUES ( '$newlogin', '$hash' );"

As a result, the database is written:
7677e1189f8dc414d07512357e38f5d49355def281e3cdb7f9a67eb6c46455f3
A php php once scanned again in the browser displays:
hash from the db: 7677e1189f8dc414d07512357e38f5d49355def281e3cdb7f9a67eb6c46455f3
generated hash: ae87f97a6cbf8f2c3967fcc012195493cf42062e61ecc79ecc861eb2720acc49
Everything happens in utf-8. Both php and base. But, apparently, when writing to the database, the hash changes
. Where did I mess up?

Answer the question

In order to leave comments, you need to log in

5 answer(s)
V
Vladimir Martyanov, 2015-09-03
@IsaevDev

You are checking incorrectly: you need to display the generated value, add it to the database and see what was added to the database.

S
SagePtr, 2015-09-03
@SagePtr

where is salt stored?

S
sbh, 2015-09-03
@sbh

It is possible in more detail how rows are formed:
hash from db:
generated hash:
?
Look closely at the generated hash:

M
MetaDone, 2015-09-03
@MetaDone

Is $salt randomly generated by any chance? then it converges - you have a new value for each operation

G
Galimzhan Gabdreshov, 2015-10-31
@Galanit

can encryption and decryption go?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question