From 69cf46d89bd6841ae667a4ebf56a6486b7c2fe1a Mon Sep 17 00:00:00 2001 From: Margashi Thakur Date: Tue, 13 Oct 2020 22:58:14 +0530 Subject: [PATCH] added py script to create captcha image --- captcha.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 captcha.py diff --git a/captcha.py b/captcha.py new file mode 100644 index 0000000..6030a03 --- /dev/null +++ b/captcha.py @@ -0,0 +1,30 @@ +import random +import string + +from PIL import Image +from PIL import ImageDraw +from PIL import ImageFont + +img = Image.new('RGB', (200, 100)) +d = ImageDraw.Draw(img) + +len = random.randint(0, 10) +captcha = "" +for i in range(len): + r2 = random.randint(0, 10) + if(r2 < 6): + r3 = random.randint(0, 10) + else: + r3 = random.choice(string.ascii_letters) + captcha = captcha + str(r3) + +print("Captcha of length", len, "is", captcha) +d.text((20, 20), captcha, fill=(255, 0, 0)) +img.save('s.png') + +print("Captcha: ", captcha) +user_inp = input("Enter captcha: ") +if(user_inp == captcha): + print("Validated") +else: + print("Unvalid entry")