Storing hexadecimal values as binary in MySQL

后端 未结 6 955
情话喂你
情话喂你 2020-12-15 08:42

I was thinking about how I\'m storing passwords in my database : appropriately salted SHA1 strings in a CHAR(40) field. However, since the character data in there is actuall

6条回答
  •  北荒
    北荒 (楼主)
    2020-12-15 08:54

    This is an old question but I noticed nobody has mentioned data validation as an advantage to a BINARY column. Specifically, it is possible to store an invalid value in a CHAR(40) column by using characters that are not hex digits (0-9, a-f).

    You could still insert the wrong value into the BINARY column (for example, if you forget to call UNHEX), but you will never have to consider reading a value from the database that doesn't parse correctly.

提交回复
热议问题