1

I have the following code in php:

$salt = bin2hex(openssl_random_pseudo_bytes(22));
$hash = crypt($this->input->post("defpswd"), "$2y$12$".$salt);

If i try to save $hash value to a MSSQL database table with a varbinary datatype field, i get the error message:

[Microsoft][ODBC SQL Server Driver][SQL Server]Implicit conversion from data type varchar to varbinary is not allowed. Use the CONVERT function to run this query.

$hash variable contains:

'$2y$12$35695d29f921c713eba4fu1VY0q6VF6HryPH9HjiLvHOoupXWvPn.'

If i cast $hash by using binary as in is it possible to convert a string to varbinary in PHP without using the SQL function i get the same error. I am using CodeIgniter and MSSQL database with an odbc connection. What is it that i am not getting right? Thank you.

Community
  • 1
  • 1
NetizenKing
  • 95
  • 1
  • 11

1 Answers1

0

$hash is not binary it is a character string, it has been Base64 encoded and Base64 is a character (ASCII). Just use the varchar DB type.

There is no reason to cast it to varbinary.

zaph
  • 111,848
  • 21
  • 189
  • 228