title: Should I use password hash as secret key in HMAC?
body: <p>I am trying to build a password reset / forgotten password link. The link would be sent by email to the user. So far, I'm taking this approach:</p>
  
  <ol>
  <li><p>Generate token using <code>bin2hex(openssl_random_pseudo_bytes(16));</code> </p></li>
  <li><p>Store a <strong>hash</strong> of this token in a db table</p></li>
  <li><p>Store an expiry time for it.</p></li>
  </ol>
  
  <p>The url would be <code>/reset-password/{$email address}/{$token}</code></p>
  
  <p>I'd like to add an HMAC to the url. If I do so, can I use that user's password hash (<strong>Edit: - hash created using <code>password_hash()</code> in PHP5.5</strong>) as the secret key safely? e.g.</p>
  
  <pre class="lang-php prettyprint-override"><code>$hmac = hash_hmac('sha256', $url_without_hmac, $password_hash);
  </code></pre>
  
  <p>so the new url would be <code>/reset-password/{$email_address}/{$token}/{$hmac}</code></p>
  
  <p>and the hmac would enable us to verify that the url is genuine without having a globally stored secret key. Does this seem a safe approach, use of email to send the link notwithstanding?</p>