title: Storing hexadecimal values as binary in MySQL
body: <p>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 actually just a hex representation of a 160 bit number, I thought it might be better to store it as BINARY(20).</p>
  
  <pre><code>CREATE TABLE users (
      password BINARY(20)
      /* snip */
  );
  
  INSERT INTO users (password) VALUES (UNHEX(SHA1('mypassword'));
  </code></pre>
  
  <p>As I see it, one benefit of this approach is that it halves the size of that field, but I can imagine there's probably some downsides too.</p>
  
  <p>What's your opinion?</p>