title: IPBoard password hashing issue, doesn't match algorithm
body: <p>A quick link to the IPBoard page explaining that the forum uses the standard <code>md5(md5($salt).md5($password))</code> format that most forums use can be found here: <a href="https://www.invisionpower.com/support/guides/_/advanced-and-developers/miscellaneous/passwords-in-ipboard-r130" rel="nofollow">https://www.invisionpower.com/support/guides/_/advanced-and-developers/miscellaneous/passwords-in-ipboard-r130</a></p>
  
  <p>I actually come from using MyBB which uses the same structure, so I would have thought just changing the table/column names in my query would make for a relatively simple switch, boy was I wrong.</p>
  
  <p>The original query that I had used was the following</p>
  
  <pre><code>SELECT * FROM `forum_members` WHERE `name`=? AND `members_pass_hash`= MD5(CONCAT(MD5(members_pass_salt), MD5(?)))"
  </code></pre>
  
  <p>This is a prepared statement, in which the username and the raw password are provided by my server. This unfortunately was not working, I took a few steps and started to debug the data, instead of using the SQL MD5 function I grabbed the data and performed MD5 checks in Java to get a better idea of what was going on.</p>
  
  <p>To do this, I used the following MD5 function I've used for a long time:</p>
  
  <pre><code>public String MD5(String md5) {
             try {
                  java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
                  byte[] array = md.digest(md5.getBytes());
                  StringBuffer sb = new StringBuffer();
                  for (int i = 0; i &lt; array.length; ++i) {
                    sb.append(Integer.toHexString((array[i] &amp; 0xFF) | 0x100).substring(1,3));
                 }
                  return sb.toString();
              } catch (java.security.NoSuchAlgorithmException e) {
              }
              return null;
          }
  </code></pre>
  
  <p>This yielded some slightly strange results, in which the data wasn't matching up.</p>
  
  <pre><code>Database salt: *nzFC 
  Database hash: 6bac5cba673134ea084e481b57921134
  Server generated hash: d7f94e3f262e7dee81b12ac087c42b18
  </code></pre>
  
  <p>The server generated has was generated by using the <code>MD5(MD5(salt) + MD5(rawpassword))</code> method the other forums use, including IPB. This worked on MyBB, so I'm a bit flustered. </p>
  
  <p>I've checked for things such as capitalization problems, etc, but I'm coming up absolutely blank. </p>