Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
afnan47
GitHub Repository: afnan47/sem7
Path: blob/main/CSDF/2. Implement a program to generate and verify CAPTCHA image/captcha.py
426 views
1
import random
2
3
def checkCaptcha(captcha, user_captcha):
4
if captcha == user_captcha:
5
return True
6
return False
7
8
def generateCaptcha(n):
9
chrs = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
10
captcha = ""
11
while(n):
12
captcha += chrs[random.randint(1, 1000) % 62]
13
n -= 1
14
return captcha
15
16
if __name__ == "__main__":
17
#Length of captcha
18
n = 9
19
captcha = generateCaptcha(9)
20
print(captcha)
21
22
user_captcha = input("Enter the captcha:")
23
if(checkCaptcha(captcha, user_captcha)):
24
print("CAPTCHA Matched!")
25
else:
26
print("CAPTCHA Not Matched")
27