Advertisement
pleasedontcode

SMS OTP Generation (Server-Side)

Nov 7th, 2024
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.39 KB | Source Code | 0 0
  1. from twilio.rest import Client
  2. import random
  3.  
  4. def send_otp(phone_number):
  5.     otp = str(random.randint(100000, 999999))  # Generate a 6-digit OTP
  6.     client = Client("TWILIO_ACCOUNT_SID", "TWILIO_AUTH_TOKEN")
  7.     message = client.messages.create(
  8.         body=f"Your OTP code for door access is {otp}",
  9.         from_="YOUR_TWILIO_PHONE_NUMBER",
  10.         to=phone_number
  11.     )
  12.     return otp
  13.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement