title: Best practice for two way hashing in python?
body: <p>I want to allow users to validate their email address by clicking on a link. The link would look something like</p>
  
  <p><a href="http://www.example.com/verifyemail?id=some-random-string" rel="nofollow noreferrer">http://www.example.com/verifyemail?id=some-random-string</a></p>
  
  <p>When I am sending this email, I want to be able to easily generate this 'some-random-string' from row id of user, an integer. and when user clicks on this link, generate that integer back.</p>
  
  <p>Only requirement is this 'some-random-string' should be as opaque and non-guessable to the user as possible.</p>
  
  <hr>
  
  <p>Finally, this is what I settled on</p>
  
  <pre><code>def p3_encrypt_safe(plain, key):
      return base64.urlsafe_b64encode(p3_encrypt(plain, key))
  </code></pre>
  
  <p>used the nice crypto library from <a href="http://www.nightsong.com/phr/crypto/p3.py" rel="nofollow noreferrer">http://www.nightsong.com/phr/crypto/p3.py</a>
  addition of base64 safe encoding is mine.</p>