Send OTP Using Python

Send OTP Using Python

In this tutorial are going to make a real-time GUI to Send OTP Using Python. For this project, we are going to use four modules namely Tkinter, Requests, Random, and JSON.

Tkinter will be used for creating the UI.

Requests will be used to send a GET request to the site.

JSON will be used for setting the parameters and the random module will be used for generating the OTP.

Also, you need to create an account on fast2sms. Creating an account is very simple. Go to http://www.fast2sms.com and create an account for free. As a new user, you will receive a 50 rupees balance in your wallet.

Now Goto Dev API and generate your API. Copy your unique API and paste it into the JSON part of the code.

Complete Code to Send OTP Using Python

from tkinter import *
import tkinter.messagebox as tsmg
import requests
import random
import json

root=Tk()

rand=random.randint(1,999999)

msg=f"Your One Time Password(OTP) is {rand}"

def sms_send(a,msg):
    url="https://www.fast2sms.com/dev/bulk"
    params={
   // Paste Your Unique API Here in-place of ************
        "authorization":"*************",
        "sender_id":"SMSINI",
        "message":msg,
        "language":"english",
        "route":"p",
        "numbers":a
    }
    rs=requests.get(url,params=params)


def send():
    a=num.get()
    if(a==""):
        tsmg.showerror("Error","Enter Your Mobile Number")
    elif (len(a)<10):
        tsmg.showerror("Error","Invalid Mobile Number")
        num.set("")
    else:
        b=tsmg.askyesno("Info",f"Your Number is {a}")
        if(b==True):
            sms_send(a,msg)
        else:
            num.set("")

def check():
    c=otp.get()
    if(c==""):
        tsmg.showerror("Error","Enter OTP")
    else:
        if(str(rand)==c):
            tsmg.showinfo("Info","Successful")
        else:
            tsmg.showerror("Error","Invalid OTP")
            num.set("")
            otp.set("")


root.geometry("500x500")
root.title("OTP-Checker")

num=StringVar()
otp=StringVar()

f1=Frame(root)
Label(f1,text="Check Your OTP",font="SegoeUI 30 bold",fg="purple").pack(padx=5,pady=10)
f1.pack(fill=BOTH)

f2=Frame(root)
Label(f2,text="Enter Your Number",font="SegoeUI 20 bold",fg="teal").pack(padx=5,pady=5)
e1=Entry(f2,textvariable=num,font="SegoeUI 14 bold",fg="black",bg="white",relief=SUNKEN,borderwidth=4,justify="center").pack(ipady=5)
f2.pack(fill=BOTH,padx=5,pady=10)

f3=Frame(root)
Label(f3,text="Enter OTP",font="SegoeUI 20 bold",fg="teal").pack(padx=5,pady=5)
e2=Entry(f3,textvariable=otp,font="SegoeUI 14 bold",fg="black",bg="white",relief=SUNKEN,borderwidth=5,justify="center").pack(ipady=5)
f3.pack(fill=BOTH,padx=5,pady=10)

f4=Frame(root)
Button(f4,text="Send OTP",command=send,font="SegoeUI 10 bold",fg="purple").pack(padx=20,pady=10,side=LEFT)
Button(f4,text="Check OTP",command=check,font="SegoeUI 10 bold",fg="purple").pack(padx=40,pady=10,side=LEFT)
f4.pack()


root.mainloop()

Output:

Send OTP Using Python
Send OTP Using Python

Hope You All Liked This Project.
Comment Down Your Views/QUERIES if you have.


Also Read:

  • Print Colored Text Output in Python
    Introduction Command line applications often return text in the same color as the terminal. There are times when we wish to draw the user’s attention to output, such as a warning or error message. In certain circumstances, a splash of color may make all the difference. This article demonstrates how to Print Colored Text Output…
  • Gender Recognition by Voice using Python
    In this article, we are going to build a project on Gender Recognition by Voice using Python in Machine Learning. This is an era of technology and everyone is using technology nowadays as it’s making our lives so easier. ML models are used in various sectors and also in real-time recognition as well. One of…
  • Make money with Python in 2022
    Hello friends, do you know there are many ways to can make money with Python? Yes, I am not joking, this is absolutely real, anyone even a beginner can money with Python or any other technology/programming language. We are not lying, today, we are going to tell you the top 10 real and 100% working…
  • Top 15 Python Libraries For Data Science in 2022
    Introduction In this informative article, we look at the most important Python Libraries For Data Science and explain how their distinct features may help you develop your data science knowledge. Python has a rich data science library environment. It’s almost impossible to cover everything in a single article. As a consequence, we’ve compiled a list…
  • Top 15 Python Libraries For Machine Learning in 2022
    Introduction  In today’s digital environment, artificial intelligence (AI) and machine learning (ML) are getting more and more popular. Because of their growing popularity, machine learning technologies and algorithms should be mastered by IT workers. Specifically, Python machine learning libraries are what we are investigating today. We give individuals a head start on the new year…
  • File Explorer in Python using Tkinter
    Introduction Welcome to copyassignment.com. In this tutorial, we are going to learn File Explorer in Python using the Tkinter module. What is basically a file explorer? A file explorer is nothing but an application that is used to manage certain files and folders on your device where we can open, edit, copy, delete and move…
  • Drawing Application in Python Tkinter
    Introduction In this article, we will design and construct a basic Drawing Application in Python Tkinter GUI, where we can simply draw something on the canvas using a pencil and erase with an eraser, as well as the ability to change the thickness of a pencil and eraser. We may also modify the canvas’s background…
  • Sequel Programming Languages(SQL)
    In this article, we are going to learn about Sequel Programming Languages(SQL). Big enterprises like Facebook, Instagram, and LinkedIn, use SQL for storing the data in the back-end. So, If you want to get a job in the field of data, then it is the most important query language to learn. Before getting started, let…
  • Run Python Code, Install Libraries, Create a Virtual Environment | VS Code
    Visual Studio Code is one of the most efficient code compilers/interpreters. It is very promising because of the vast and widely available go-to extensions that help programmers. This article is an elaborative detail about how we can run Python code, install Python libraries, and create a virtual environment in Visual Studio Code. Write and Run…
  • Top 32 Python Interview Questions For Experienced
    Introduction Being an expert in a programming language may guarantee you a good salary and a rewarding job. Among the hundreds of programming languages presently accessible, Python has moved to the top of the list of the most popular. Let’s start at the beginning with some general Python Interview Questions For Experienced. These are the…

Share:
Avatar of Dhruv Paghdal

Author: Dhruv Paghdal