0% found this document useful (0 votes)
28 views14 pages

Pavithrakavya Mini Project Report

Uploaded by

laxman Nyamtabad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views14 pages

Pavithrakavya Mini Project Report

Uploaded by

laxman Nyamtabad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 14

DEEKSHA DEGREE COLLEGE

Near New Bus Stand, Nirmal

DEPARTMENT OF DATA SCIENCE


A MINI PROJECT REPORT
ON
Simple OTP Generator

Submitted in partial fulfillment


for the award of Bachelor of Science
In
DATA SCIENCE
Submitted by

N.PAVITHRA 321244312
B.KAVYA 321244303
DURING
3RD SEMESTER 2024-2025

Reviewed by

Mr. LAXMAN NYAMTABAD


Asst. Professor

1
DEEKSHA DEGREE COLLEGE
Near New Bus Stand, Nirmal

DEPARTMENT OF DATA SCIENCE

Certificate

This is to certify that the mini project work titled


Simple OTP Generator

Submitted in partial fulfillment of the degree of Bachelor of


Engineering
N.PAVITHRA 321244312
B.KAVYA 321244303

DURING
3RD SEMESTER 2024-2025

Signature of Reviewer Signature of HOD

2
CONTENTS

ABSTRACT 4

ACKNOWLEDGEMENT 5

INTRODUCTION

1.1. DEFINITION 1
1.2. OBJECTIVES 1
1.3. HARDWARE AND SOFTWARE REQUIREMENTS

2. DATASTRUCTURES
2.1. STRINGS 5
2.2. LISTS 6
2.3. INTEGERS
2.4. BOOLEANS

3. IMPLEMENATION 20
3.1. Generating a Numeric OTP
3.2. Customizing OTP Length
3.3. OTP Verification Process
3.4. Testing the OTP Generator
4. RESULTS 23

5. CONCLUSION 25

6.

3
ABSTRACT

The project involves the creation of an OTP generation system that produces a
random, numeric OTP. The OTP is sent to the user (optionally via email) and is valid only for
a limited time to ensure security. The user is then prompted to input the OTP, which is
validated by the system. If the OTP matches and has not expired, the system grants access;
otherwise, it displays an error message indicating that the OTP is invalid or expired.

The project serves as a practical example of implementing basic security features in


Python and is a stepping stone toward developing more advanced multi-factor
authentication (MFA) systems. It provides valuable insights into the principles of secure user
authentication, expiration handling, and email communication in Python applications

4
ACKNOWLEDGEMENT

I would like to express my sincere gratitude to everyone who has supported and guided me
throughout the development of this Python mini project on the OTP Generator.

First and foremost, I would like to thank my project supervisor for their valuable
guidance, insightful suggestions, and continuous support throughout the course of this
project. Their expertise and encouragement have been instrumental in completing this
project successfully.

I also extend my heartfelt thanks to my family and friends for their constant
encouragement and understanding, which kept me motivated during the course of this
project.

A special thanks to of our project guide LAXMAN NYAMTABAD as well as our principal
M.SRIDHAR Garu who have the golden opportunity to do this wonderful project on the
topic SIMPLE OTP GENERATOR, which also helped us in doing a lot of research and we
came to know about so many new things we are really thankful to them
secondly I would also like to thank my parents and friends who helped me a lot in
finalizing this project within the limited time frame
Lastly, I would like to acknowledge the Python programming community, whose
open-source contributions and collaborative spirit have made it possible to create this
project with the rich libraries and modules available.

Thank you all for your contributions and support.

5
INTRODUCTION

In this project, we will create a Simple OTP Generator in Python. This generator will
generate a random OTP that can be sent to the user for authentication purposes. OTPs can
either be numeric or alphanumeric, and we will focus on generating numeric OTPs in this
example for simplicity.

In today’s digital world, ensuring security is crucial, especially for applications that
require user authentication. One-time passwords (OTPs) are widely used to verify the
identity of users during login or sensitive transactions. An OTP is a unique password that is
valid for only one session or transaction, providing an additional layer of security to prevent
unauthorized access.

Objectives:

Key Features of the Simple OTP Generator:

Randomness: The OTP will be generated randomly to ensure that it is unique every time.
Fixed Length: The length of the OTP can be customized.
Time-based Expiry: The OTP will expire after a certain amount of time (optional feature).
Security: Since OTPs are short-lived, they are a secure way to ensure that only the intended
user can access a system or service.
Technologies Used:
Python: Programming language to implement the OTP generator.
Random module: For generating random numbers to create the OTP.
Time module: For managing OTP expiry (optional feature).
Use Case:This simple OTP generator can be used in any Python-based web or desktop
application where user verification is needed.
Examples include:
o User login systems
o Transaction verification
o Account recovery systems

6
In the upcoming sections, we will demonstrate how to implement the OTP generator in
Python.

Let’s begin with the code to generate a numeric OTP.

Analysis:
o A 6-digit numeric OTP can be generated easily using Python's random.randint().
However, in real-world applications, additional complexity (like adding
alphanumeric characters or increasing the OTP length) may be necessary
depending on the security requirements.
o OTPs are often generated with varying lengths (e.g., 6 digits or 8 digits) based on
the sensitivity of the system they are used to protect. Longer OTPs are harder to
guess.
Objective: To create a basic OTP (One-Time Password) generator using Python, allowing
users to authenticate their identity securely.

Requirements:
In order to develop a Simple OTP Generator project, both hardware and
software requirements. The following are the key requirements for the project:

software requirements:
- Python Libraries and Modules
- Internet Connection (if Email Service is Used)
- Python version: Python 3.6
- Operating system: windows 10

Hardware Requirements:

Processor: Intel Pentium 4 or more

- Ram: At least 2 GB of RAM to ensure smooth execution


- Hard disk: 120 GB hard

7
ALGORITHM:
The OTP Generator project relies on a straightforward algorithm for generating,
validating, and expiring One-Time Passwords (OTPs).The algorithm's main
purpose is to provide secure, temporary, and random passwords for
authentication purposes.

1. OTP Generation Algorithm


Input:
 User request for an OTP.
 Optional: Email address to send OTP to.
Output:
 A randomly generated OTP (numeric or alphanumeric).
 Optional: The OTP is sent to the user’s email.
Steps:
1.Initialize OTP Parameters:

 Define the length of the OTP (e.g., 6 or 8 digits).


 Optionally, define the expiration time (e.g., 5 minutes).
 Set the validity duration for the OTP.
2.Generate Random OTP:
 Using Python’s random or secrets module, generate a random OTP
of the specified length.
 Example for numeric OTP (6 digits): otp = random.randint(100000,
999999)
 Example for alphanumeric OTP (6 characters): otp =
''.join(random.choices(string.ascii_letters + string.digits, k=6))
3.Store OTP with Timestamp:
 Capture the current timestamp when the OTP is generated using the
time.time() function or datetime.now().
 Store this timestamp along with the generated OTP to track its
expiration time.
4.Send OTP to User (optional):

8
 If email integration is enabled, use the smtplib module to send the
OTP to the user's email address.
 Format the email body with the OTP and expiration message.
 Example: Send OTP to the provided email address using an SMTP
server (e.g., Gmail).
Return OTP:
 Provide the generated OTP to the user, either via email (if email
integration is used) or print it on the screen for CLI-based
interaction.

Strings
Usage: The OTP is generated as a string of characters (either numeric or
alphanumeric).

How it is used: When generating a numeric or alphanumeric OTP, Python


constructs the OTP as a string by joining individual characters or digits
together.

Example:
otp = ''.join([str(random.randint(0, 9)) for _ in range(6)])
This line generates a 6-digit OTP by joining individual digits into a string.
Reason for Use:
The OTP is treated as a string because it's easier to handle and
display to users. A string can be easily checked for correctness (i.e.,
when a user inputs the OTP, it's compared as a string).
Lists
Usage: A list is used when generating the OTP to store individual digits
before joining them into a complete OTP string.

How it is used: In the generation process, a list comprehension creates a


list of random digits, which are then joined into a string.

otp = ''.join([str(random.randint(0, 9)) for _ in range(length)])

9
In this case, the list stores each digit as a string, and join() is used to combine them into one
continuous string.

Integers

Usage: Integers are used throughout the project, particularly in the generation of numeric
OTPs and to track timestamps and expiry times.

Example:

expiry_time = 300 # OTP expires in 5 minutes (300 seconds)

current_time = int(time.time()) # Current time in seconds

Booleans
Usage: Boolean values are used to determine if the OTP entered by the user is valid and
whether it has expired.

if current_time - otp_timestamp > expiry_time:

return False # OTP expired

if input_otp == generated_otp:

return True # OTP is valid

Implementing
Generating a Numeric OTP:

Explanation and code to generate a random numeric OTP.

import random

def generate_otp(length=6):

otp = ''.join([str(random.randint(0, 9)) for _ in


range(length)])

return otp

print(generate_otp(6)) # Example: 123456

10
Customizing OTP Length:

Show how the length of the OTP can be customized by passing an argument to the function.

print(generate_otp(8)) # Example: 12345678

OTP Verification Process


OTP Input: Show how the system prompts users to input the OTP they received (via
email, SMS, etc.).
Verification: Code to verify the input OTP and check if it is valid.
def verify_otp(input_otp, generated_otp, otp_timestamp,
expiry_time):
if input_otp == generated_otp and
is_otp_valid(otp_timestamp, expiry_time):
print("OTP Verified Successfully")
else:
print("Invalid OTP or OTP Expired")
Testing the OTP Generator:
Test Case 1: Generate OTP and verify it within the validity period.
Test Case 2: Simulate OTP expiry and verify that the OTP is no longer valid.
Test Case 3: Handle invalid OTP input and display appropriate error messages.

Here’s a simple Python code to generate and validate an OTP (One-Time Password) without
involving any email functionality.

11
Simple OTP Generator in Python:

import random

import time

# Function to generate OTP

def generate_otp(length=6):

otp = ''.join(random.choices("0123456789", k=length)) #


Generate a random 6-digit OTP

timestamp = time.time() # Get current timestamp

return otp, timestamp

# Function to check if OTP is expired

def is_otp_expired(timestamp, expiry_time=300):

current_time = time.time() # Get the current time

if current_time - timestamp > expiry_time: # expiry_time


is in seconds (default 5 minutes)

return True

return False

# Function to validate the OTP

def validate_otp(user_input, generated_otp, timestamp):

if is_otp_expired(timestamp): # Check if the OTP has


expired

return "OTP Expired"

12
if user_input == generated_otp: # Check if the user input
matches the generated OTP

return "OTP Valid"

else:

return "Invalid OTP"

# Example usage

if __name__ == "__main__":

# Generate OTP

otp, timestamp = generate_otp()

print(f"Generated OTP: {otp}")

# Ask user to enter OTP

user_input = input("Enter OTP: ")

# Validate OTP

result = validate_otp(user_input, otp, timestamp)

print(result)

Example Output:

Generated OTP: 123456

Enter OTP: 123456

OTP Valid

Or if the OTP expires:

Generated OTP: 987654

Enter OTP: 987654

OTP Expired

CONCLUSION

13
The Simple OTP Generator project demonstrates the implementation of a basic yet
effective authentication mechanism using One-Time Passwords (OTPs). The system
generates random OTPs that are valid for a limited period (e.g., 5 minutes) and validates
them upon user input. This project provides a strong foundation for understanding the core
concepts of OTP generation, expiration, and validation.

In conclusion, this project provides a solid introduction to the principles of secure


authentication systems and the implementation of OTP-based authentication in Python. It
serves as a foundational piece that can be expanded into more complex systems with
additional features and enhanced security measures.

14

You might also like