forked from anshrathod/Basic-Python-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcaptcha-124.py
More file actions
77 lines (63 loc) · 1.63 KB
/
captcha-124.py
File metadata and controls
77 lines (63 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from captcha.image import ImageCaptcha
from captcha.audio import AudioCaptcha
import random, time
from PIL import Image
from playsound import playsound
def randomiseString():
r1 = random.randint(6, 10)
cap = ""
for i in range(r1):
r2 = random.randint(0, 10)
if r2 <= 5:
cap += str(random.randint(0, 9))
else:
cap += random.choice(
[chr(x) for x in range(ord("a"), ord("z") + 1)]
# + [chr(x) for x in range(ord("A"), ord("Z") + 1)]
)
return cap
def randomiseNumbers():
r1 = random.randint(4, 6)
cap = ""
for i in range(r1):
cap += str(random.randint(0, 9))
return cap
tries, i = 3, 0
# image captcha
image = ImageCaptcha(width=400, height=150)
data = randomiseString()
image.write(
data, "out.png",
)
im = Image.open("out.png")
im.show()
print("Enter the captcha : ")
while True:
valid = input()
if valid == data:
print("Captcha Validated")
break
else:
i += 1
if i == tries:
print("Failed! The captcha was", data)
break
print("Wrong input! Try again")
# audio captcha
nums = randomiseNumbers()
audio = AudioCaptcha()
audio.write(nums, "out.wav")
playsound("out.wav")
i = 0
print("Enter the captcha : ")
while True:
valid = input()
if valid == nums:
print("Captcha Validated")
break
else:
i += 1
if i == tries:
print("Failed! The captcha was", nums)
break
print("Wrong input! Try again")