title: HASHBYTES of varchar returning incorrect hash value
body: <p>I currently have a database schema that contains a user's password in plain text.  I've added a new column called password of type binary(16) with the intent of hashing the current plain text password via MD5.  When I do this, I'm finding that the value stored in the password field is wrong.  Here's my conversion query:</p>
  
  <p><code>UPDATE my_table SET password=HASHBYTES('MD5', plain_text_password);</code></p>
  
  <p>For one of my records, the plain text password is asdf.  The correct MD5 value of this is <code>0x912ec803b2ce49e4a541068d495ab570</code>.  However, the record is being updated to <code>0xEC81AFD2DF2BDA47850F9182F4AC300D</code> instead.</p>
  
  <p>Has anyone every seen issues like this before?  I'm using SQL Server 2008.</p>
  
  <p><strong>Update:</strong>
  Thinking about this a little more, I converted the plain text password field from varchar(MAX) to varchar(50).  It displays the same way within SQL management studio, but I'm wondering if the underlying encoding from when the data was in varchar(MAX) format somehow got copied over to the new varchar(50) format, causing the discrepancy.</p>