0

I want to send an OTP to the user's email Id. I checked I can send the eamil through the Django's

send_eamil()  

method with random no. I am using the following to generate the random no.

from django.utils.crypto import get_random_string

otp = get_random_string(6, allowed_chars='0123456789')

Now my question is how I can make it valid for a specific time in backend.

Should I use session or cache or something else to store the otp.

I have hardtime to figure out this.

chirag soni
  • 936
  • 10
  • 20

1 Answers1

0

create a file with XXXX-NNNNNNNNN, where XXXX is the otp and NNNN is the timestamp, then check first the OTP and then the compare the recorded timestamp with the current time

Emin
  • 573
  • 3
  • 13
  • Do you mean normal .py fie? if yes then please elaborate a little bit about way of storing the data and timestamp. It would be appreciated highly. – chirag soni May 03 '19 at 13:26
  • I mean a regular temporary text file (if under linux, place it in /tmp so it gets automatically cleaned) – Emin May 03 '19 at 14:02
  • What would be the impact if I store in cache instead? Please go ahead with good answer – chirag soni May 03 '19 at 14:09
  • Not familiar with django, so dont know what you mean by cache. Session would not work as it is bound to a browser – Emin May 04 '19 at 11:11