To Generate a One Time Password or Unique Identification URL | A Python3 Program to generate OTP ( One Time Password ) ; A Function to generate a unique OTP everytime ; All possible characters of my OTP ; String to hold my OTP ; Driver code ; Declare the length of OTP
import random NEW_LINE def generateOTP ( length ) : NEW_LINE INDENT str = " abcdefghijklmnopqrstuvwxyzAB\ STRNEWLINE TABSYMBOL CDEFGHIJKLMNOPQRSTUVWXYZ0123456789" ; NEW_LINE n = len ( str ) ; NEW_LINE OTP = " " ; NEW_LINE for i in range ( 1 , length + 1 ) : NEW_LINE INDENT OTP += str [ int ( random . random ( ) * 10 ) % n ] ; NEW_LINE DEDENT return ( OTP ) ; NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT length = 6 ; NEW_LINE print ( " Your ▁ OTP ▁ is ▁ - ▁ " , generateOTP ( length ) ) ; NEW_LINE DEDENT