tags:

views:

24

answers:

1

I'm hashing using sha256 and outputting it in binary, and storing it in Mysql's BINARY(32).

 echo $testsha256 = hash( 'sha256', "aKyAmNsb", true );

However, when I retrieve this value from the database, it's Different

 print_r(str_split($returnedpassword));
 echo "<br>";
 print_r(str_split($testsha256));
 echo "<br>";

Array ( [0] => ú [1] => È [2] => c [3] => [4] => u [5] => k [6] => ë [7] => a [8] => Ð [9] => ‰ [10] => V [11] => û [12] => E [13] => [ [14] => [15] => Ø [16] => Ý [17] => Q [18] => â [19] => ž [20] => ? [21] => [22] => ¾ [23] => ¨ [24] => ÷ [25] => 9 [26] => í [27] => Ž [28] => [29] => 5 [30] => ˆ [31] => )

Array ( [0] => ú [1] => È [2] => c [3] => [4] => u [5] => k [6] => ë [7] => \ [8] => a [9] => Ð [10] => ‰ [11] => V [12] => û [13] => E [14] => [ [15] => [16] => Ø [17] => Ý [18] => Q [19] => â [20] => ž [21] => ? [22] => [23] => ¾ [24] => ¨ [25] => ÷ [26] => 9 [27] => í [28] => Ž [29] => [30] => 5 [31] => ˆ )

As you can see, the binary returned from Mysql is missing a '\' before 'a' on index 8. Index 8 should hold '\', as it does in the $testsha256, but the '\' is not there in the $returnedresult

+1  A: 

Use mysql_real_escape_string when inserting the hash into the database.

Mark Byers