title: How to generate Time based One Time Password(OTP) with Django
body: <p>I am generating a random string as OTP using the following code - </p>
  
  <pre><code>from django.utils.crypto import get_random_string
  
  otp = get_random_string(6, allowed_chars='0123456789')
  </code></pre>
  
  <p>The problem with this is due to SMS delivery issues people request for a lot of OTPs and then when they arrive together they have no idea which one is currently valid. </p>
  
  <p>I want to generate a OTP that wouldn't change for <strong>30 minutes</strong> and is unique for every phone number which would be something like <strong>+919999999999</strong>. </p>