0% found this document useful (0 votes)
29 views15 pages

PWP MP

Uploaded by

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

PWP MP

Uploaded by

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

D.Y.

PATIL TECHNICAL CAMPUS, TALSANDE


FACULTY OF ENGINEERING & FACULTY OF
MANAGEMENT
(Polytechnic)

A Micro project Report On


“Captcha Generator Using Python”

Submitted By

Enrollment No. Name

2112200014 Kolekar Atharv Milind

Guided By
Miss. Gurav J. N.

D.Y.PATIL TECHNICAL CAMPUS, TALSANDE FACULTY OF


ENGINEERING & FACULTY OF MANAGEMENT
(Polytechnic)

DEPARTMENT OF COMPUTER ENGINEERING


SEMESTER VI
CERTIFICATE

This is Certify that student of Computer Engineering has


successfully completed the project term work “Captcha Generator Using
Python” in partial fulfilment of the Diploma of Engineering in Computer as
laid down during academic year 2023-24.

Roll No. Name of Student Exam Seat No.


3201 Kolekar Atharv Milind

Miss. Gurav J. N. Mr. Kumbhar R. S.


Project Guide HoD

Dr. S.R. Pawaskar


Principal

Date – / /2024
Place – Talsande
INDEX

Sr No. Title Page no.

1 Introduction 4

2 Real Time Use of Project 5-6

3 Pre-requisites 7

4 Requirements 8

5 Algorithm 9

6 Program Code 10 - 11

7 Output 12 - 13

8 Conclusion 14

9 References 15
Captcha Generator Using Python

Introduction

Python is a versatile programming language that you can use across applications in
automation, web development, data analysis, and more. You can use Python to automate real-
world tasks such as monitoring websites, sending emails, and generating passwords and also
captchas.

This report outlines the development of a Random CAPTCHA Generator using


Python, designed to enhance web security by distinguishing between human users and
automated bots. The project leverages Python's simplicity and versatility for rapid
development.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 4
Captcha Generator Using Python

Real Time Use of Project

1. User Registration and Login Security: CAPTCHAs are employed during user
registration and login processes.

2. Form Submission and Comment Sections: Web forms, comment sections, and
online forums often use CAPTCHAs to deter automated scripts from submitting spam
or abusive content. Python's readability and ease of integration with web frameworks
like Flask or Django facilitate the seamless implementation of CAPTCHAs in form
submissions.

3. E-commerce Transaction Security: During the checkout process in e-commerce


websites, CAPTCHAs help secure online transactions by ensuring that the interaction
is initiated and completed by a genuine human user. Python's versatility allows for the
integration of CAPTCHA solutions into various components of an e-commerce
platform.

4. Account Recovery Processes: CAPTCHAs can be incorporated into account


recovery processes to verify that the person attempting to recover an account is the
legitimate account owner. Python's support for web development frameworks
simplifies the inclusion of CAPTCHA challenges in account recovery workflows.

5. Protection Against Web Scraping: Websites with valuable data use CAPTCHAs to
deter automated scraping bots that attempt to extract information in an unauthorized
manner. Python's rich ecosystem allows for the implementation of CAPTCHA
solutions that effectively protect against web scraping.

6. Enhancing AI Training Data: CAPTCHAs can be utilized to generate labeled


datasets for training machine learning models, particularly those related to image
recognition. Python's popularity in the machine learning community makes it a
suitable choice for incorporating CAPTCHA-based datasets into AI training pipelines.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 5
Captcha Generator Using Python

7. Adherence to Security Regulations: In industries where compliance with security


regulations is mandatory, CAPTCHAs contribute to meeting these requirements.
Python's robustness and availability of security-related libraries support the
implementation of CAPTCHA solutions that align with regulatory standards.

8. Securing Online Voting Systems: CAPTCHAs can be used to secure online voting
systems, ensuring that votes are cast by human users rather than automated scripts.
Python's ease of integration with web frameworks and cryptographic libraries makes
it suitable for implementing secure online voting processes.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 6
Captcha Generator Using Python

Pre-requisites

For a simple CAPTCHA generator using Python, the prerequisites are straightforward.
Here's a concise list of what you need:

• Python Installed:
Make sure that Python is installed on your system. Download and install the latest
version of Python from the official Python website.

• Pillow Library (PIL Fork):


The Pillow library is crucial for image processing and is commonly used for
generating CAPTCHA images. Install Pillow using the following command:
pip install pillow #to install pillow library.

• Random Module:
The random module is part of the Python standard library and is used for generating
random characters or sequences for the CAPTCHA.

• Basic Image Processing Understanding:


With these prerequisites in place, you can start building a simple CAPTCHA
generator using Python. This minimal setup ensures that you have the necessary tools
for image processing and random character generation, which are the core
components of a basic CAPTCHA system

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 7
Captcha Generator Using Python

Requirements

In order to generate CAPTCHA in Python, we need the library PIL (Python Imaging
Library) installed in our system. To do that, we install a fork of the PIL library called Pillow
into our system. To do so, we type in the Command prompt:
“ pip install Pillow “
After which we can import PIL in Python to generate our captcha code.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 8
Captcha Generator Using Python

Algorithm

• Import the necessary libraries.

• Create a blank image with any colour as background

• Define the length of the CAPTCHA and join a string of random words.

• Customise the font and font size of the resulting text.

• Calculate the text size and position it in the centre.

• Draw the calculated text image with the values needed for it to print in the centre.

• Add a random assortment of noise onto the image and fill it with black.

• Define the width, height of the CAPTCHA image and the string length of the captcha.

• Save the captcha image.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 9
Captcha Generator Using Python

Program Code

import random
import string
from tkinter import Tk, Label, Entry, Button, END
from PIL import ImageTk, Image
from captcha.image import ImageCaptcha
#defining required variable in source code
def createImage(flag=0):
global random_string
global image_label
global image_display
global entry
global verify_label
if flag == 1:
verify_label.grid_forget()
entry.delete(0, END)
random_string = ''.join(random.choices(string.ascii_letters + string.digits, k=6))
image_captcha = ImageCaptcha(width=250, height=125)
image_generated = image_captcha.generate(random_string)
image_display = ImageTk.PhotoImage(Image.open(image_generated))
image_label.grid_forget()
image_label = Label(root, image=image_display)
image_label.grid(row=1, column=0, columnspan=2,
padx=10)
def check(x, y):
global verify_label
verify_label.grid_forget()
if x.lower() == y.lower():
verify_label = Label(master=root,
text="Correct",
font="Arial 15",
bg='#00ff00',

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 10
Captcha Generator Using Python

fg="#ffffff"
)
verify_label.grid(row=0, column=0, columnspan=2, pady=10)
else:
verify_label = Label(master=root,
text="Incorrect!",
font="Arial 15",
bg='#ff0000',
fg="#ffffff"
)
verify_label.grid(row=0, column=0, columnspan=2, pady=10)
createImage()
if __name__ == "__main__":
root = Tk()
root.title('Simple Captcha Generator')
verify_label = Label(root)
image_label = Label(root)
entry = Entry(root, width=10, borderwidth=5,
font="Arial 15", justify="center")
entry.grid(row=2, column=0)
createImage()
reload_button = Button(text="Refresh", command=lambda: createImage(1))
reload_button.grid(row=2, column=1, pady=10)
submit_button = Button(root, text="Submit", font="Arial 10", command=lambda:
check(entry.get(), random_string))
submit_button.grid(row=3, column=0, columnspan=2, pady=10)
root.bind('<Return>', func=lambda Event: check(entry.get(), random_string))
root.mainloop()

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 11
Captcha Generator Using Python

Output
After execution of program:

If captcha is wrong:

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 12
Captcha Generator Using Python

If the captcha is correct:

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 13
Captcha Generator Using Python

Conclusion

Generating CAPTCHA is an effective way to prevent malicious and suspicious bots


from gain in access to the website. In this present tech-blooming world, it becomes a
necessity to have CAPTCHAs for every website since it is more vulnerable to attacks and
hacks than ever before.

Consequently, due to the advancement of technology, and better OCR (Optical


Character Recognition) techniques with high accuracy implemented, some bots may be able
to bypass CAPTCHAs with relative ease. Another problem is that malicious users can build
Machine Learning algorithms and train the model based on CAPTCHAs and bypass the test
that way too.

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 14
Captcha Generator Using Python

References

1. https://www.tutorialspoint.com/generate-captcha-using-python
2. https://www.sourcecodester.com/python/15125/simple-captcha-generator-using-
python-free-source-code.html
3. https://chat.openai.com/
4. https://www.geeksforgeeks.org/generate-captcha-using-python/
5. https://medium.com/analytics-vidhya/how-to-create-your-own-captcha-with-python-
3c04e55a5d3f’
6. https://realpython.com/tutorials/projects/

D. Y. Patil Technical Campus, Talsande


Faculty of Engineering & Faculty of Management (Polytechnic) Page 15

You might also like