Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where to save the verification code sent to the user for signing up

I'm somehow new to Django and it's my first time to implementing a signUp form with sms verification.

I get the user mobile number and generate a random number and send to him; I want the generated code to be expired after 30 minutes and after that I don't need them, so it seems that it is not a good idea to save them in DB and after the expiration time, delete them.

I wonder if anybody can help me with the the question that "what is the best way to implement this?"

Thank you so much in advance

like image 745
Far Avatar asked Nov 08 '16 09:11

Far


People also ask

Where do I enter the verification code on my new iPhone?

Go to Settings > Passwords, then select your account for the website or app. Tap Set Up Verification Code, then tap Enter Setup Key.

How do I find my verification code on my iPhone?

From your iPhone, iPad, or iPod touchGo to Settings > [your name]. Tap Password & Security > Get Verification Code.

How do I find my 6 digit authentication code?

You need to install the Google Authenticator app on your smart phone or tablet devices. It generates a six-digit number, which changes every 30 seconds. With the app, you don't have to wait a few seconds to receive a text message.


1 Answers

save them in Redis. Redis keys can have a TTL(Time-To-Live), keys with TTL are deleted automatically after the time period.

import redis
r = redis.StrictRedis()

# create pin 
r.set("<phone-number>", <sms-pin>)
r.expire("<phone-number>", 1800) # 1800 seconds = 1/2 hour

# get pin
if r.exists("<phone-number>"):
    pin=r.get("<phone-number>")
    ... validate pin
else:
    ... invalid pin

More docs at http://agiliq.com/blog/2015/03/getting-started-with-redis-py/

like image 120
pragman Avatar answered Oct 07 '22 01:10

pragman