bengali-captcha 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bengali_captcha-0.1.0/LICENSE +21 -0
- bengali_captcha-0.1.0/MANIFEST.in +4 -0
- bengali_captcha-0.1.0/PKG-INFO +283 -0
- bengali_captcha-0.1.0/README.md +260 -0
- bengali_captcha-0.1.0/licenses/CLAPTCHA.txt +21 -0
- bengali_captcha-0.1.0/pyproject.toml +40 -0
- bengali_captcha-0.1.0/setup.cfg +4 -0
- bengali_captcha-0.1.0/src/bengali_captcha/__init__.py +78 -0
- bengali_captcha-0.1.0/src/bengali_captcha/__main__.py +34 -0
- bengali_captcha-0.1.0/src/bengali_captcha/_assets.py +30 -0
- bengali_captcha-0.1.0/src/bengali_captcha/_compat.py +36 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/backgrounds/cap1.png +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/backgrounds/cap3.jpg +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/fonts/Bangla.ttf +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/fonts/ben.ttf +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/fonts/ek_kolom_bold.ttf +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/assets/fonts/sole.ttf +0 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha.py +435 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha2.py +431 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha3.py +435 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha4.py +442 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha5.py +436 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha6.py +442 -0
- bengali_captcha-0.1.0/src/bengali_captcha/claptcha7.py +446 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/PKG-INFO +283 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/SOURCES.txt +29 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/dependency_links.txt +1 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/entry_points.txt +2 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/requires.txt +5 -0
- bengali_captcha-0.1.0/src/bengali_captcha.egg-info/top_level.txt +1 -0
- bengali_captcha-0.1.0/tests/test_captcha.py +148 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Bengali CAPTCHA contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bengali-captcha
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Seven Bengali CAPTCHA variants with original fonts and backgrounds included
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Keywords: bengali,bangla,captcha,pillow,image
|
|
7
|
+
Classifier: Development Status :: 3 - Alpha
|
|
8
|
+
Classifier: Intended Audience :: Developers
|
|
9
|
+
Classifier: Natural Language :: Bengali
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: OS Independent
|
|
12
|
+
Classifier: Topic :: Multimedia :: Graphics
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Requires-Python: >=3.10
|
|
15
|
+
Description-Content-Type: text/markdown
|
|
16
|
+
License-File: LICENSE
|
|
17
|
+
License-File: licenses/CLAPTCHA.txt
|
|
18
|
+
Requires-Dist: Pillow>=10.1
|
|
19
|
+
Provides-Extra: release
|
|
20
|
+
Requires-Dist: build>=1.2; extra == "release"
|
|
21
|
+
Requires-Dist: twine>=6; extra == "release"
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# Bengali CAPTCHA
|
|
25
|
+
|
|
26
|
+
**Generate Bengali (Bangla) CAPTCHA images in Python, with bundled fonts and backgrounds.**
|
|
27
|
+
|
|
28
|
+
`bengali-captcha` is a Pillow-based library for creating image CAPTCHAs with
|
|
29
|
+
Bengali letters and digits. Adapted from the `captchaWeb` research application,
|
|
30
|
+
it provides seven rendering variants through a simple Python API and supports
|
|
31
|
+
Pillow images, in-memory streams, and image files.
|
|
32
|
+
|
|
33
|
+
**The PyPI package includes the original Bengali fonts and background images.**
|
|
34
|
+
Installing it with `pip` installs those assets too. All seven CAPTCHA variants
|
|
35
|
+
select their bundled assets automatically: no font path, background path,
|
|
36
|
+
separate download, or configuration is required.
|
|
37
|
+
|
|
38
|
+
The project is associated with the research paper
|
|
39
|
+
[**A Usable and Secure Bengali CAPTCHA**](https://arxiv.org/abs/2606.29077).
|
|
40
|
+
If you use this library in your research, please cite the paper using the
|
|
41
|
+
BibTeX entry in the **Citation** section below.
|
|
42
|
+
|
|
43
|
+
## Sample CAPTCHA
|
|
44
|
+
|
|
45
|
+
## Sample CAPTCHA
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
## Features
|
|
50
|
+
|
|
51
|
+
- Seven rendering variants with automatically selected fonts and backgrounds.
|
|
52
|
+
- Bundled assets for offline generation after installation.
|
|
53
|
+
- Random Bengali challenge text generated using Python's `secrets` module.
|
|
54
|
+
- Custom challenge text, text-source callables, and configurable random-text length.
|
|
55
|
+
- Adjustable image size, margins, noise, and output format.
|
|
56
|
+
- Optional custom fonts, backgrounds, and supported text colors.
|
|
57
|
+
- Pillow image, in-memory stream, and file output.
|
|
58
|
+
- Command-line interface and a Django integration example.
|
|
59
|
+
|
|
60
|
+
## Installation
|
|
61
|
+
|
|
62
|
+
Requires **Python 3.10 or newer**.
|
|
63
|
+
|
|
64
|
+
```console
|
|
65
|
+
python -m pip install bengali-captcha
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Quick start
|
|
69
|
+
|
|
70
|
+
The original Bengali fonts and background images are included. Generate a
|
|
71
|
+
CAPTCHA immediately, with no font downloads or custom image paths:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from bengali_captcha import BengaliCaptcha
|
|
75
|
+
|
|
76
|
+
captcha = BengaliCaptcha()
|
|
77
|
+
answer, image = captcha.image
|
|
78
|
+
image.save("captcha.png")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
All seven variants work out of the box:
|
|
82
|
+
|
|
83
|
+
```python
|
|
84
|
+
for variant in range(1, 8):
|
|
85
|
+
answer, path = BengaliCaptcha(variant=variant).write(f"captcha-{variant}.png")
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
By default, the answer contains four characters from the original project's
|
|
89
|
+
Bengali alphabet and digit selection. Challenge text uses `secrets` randomness.
|
|
90
|
+
Pass `length=5` to change the length, or supply a string or callable as `source`.
|
|
91
|
+
|
|
92
|
+
To generate a longer random challenge:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
captcha = BengaliCaptcha(length=5)
|
|
96
|
+
answer, image = captcha.image
|
|
97
|
+
image.save("captcha.png")
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
## Output options
|
|
101
|
+
|
|
102
|
+
| API | Returns |
|
|
103
|
+
| --- | --- |
|
|
104
|
+
| `captcha.image` | `(answer, image)`, where `image` is a Pillow image |
|
|
105
|
+
| `captcha.bytes` | `(answer, stream)`, where `stream` is a `BytesIO` object positioned at the beginning |
|
|
106
|
+
| `captcha.write("captcha.png")` | `(answer, path)`, after writing a newly generated image to disk |
|
|
107
|
+
|
|
108
|
+
Generate image bytes using the included assets:
|
|
109
|
+
|
|
110
|
+
```python
|
|
111
|
+
captcha = BengaliCaptcha(variant=2, source="কখ১২")
|
|
112
|
+
answer, stream = captcha.bytes # BytesIO, positioned at the beginning
|
|
113
|
+
png_data = stream.getvalue()
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
To generate and save directly to a file:
|
|
117
|
+
|
|
118
|
+
```python
|
|
119
|
+
answer, path = captcha.write("captcha.png")
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
**Each access to `.image`, `.bytes`, or `.write()` creates a new image and calls
|
|
123
|
+
the text source again.** Keep the answer returned by the same call as the image
|
|
124
|
+
you display. To save that exact image, use its `.save()` method as shown in the
|
|
125
|
+
quick start.
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
## Command-line usage
|
|
129
|
+
|
|
130
|
+
```console
|
|
131
|
+
bengali-captcha captcha.png
|
|
132
|
+
bengali-captcha captcha.png --variant 1 --length 4
|
|
133
|
+
python -m bengali_captcha captcha.png --variant 7
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
These commands use the included fonts and images. The only filename required
|
|
137
|
+
is where to save the generated PNG. The command prints its answer in UTF-8.
|
|
138
|
+
|
|
139
|
+
## Django integration
|
|
140
|
+
|
|
141
|
+
Generate bytes for each request and keep the corresponding answer in the
|
|
142
|
+
user's session. For example, inside a Django view:
|
|
143
|
+
|
|
144
|
+
```python
|
|
145
|
+
from django.http import HttpResponse
|
|
146
|
+
from bengali_captcha import BengaliCaptcha
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def captcha_image(request):
|
|
150
|
+
answer, stream = BengaliCaptcha().bytes
|
|
151
|
+
request.session["captcha_answer"] = answer
|
|
152
|
+
response = HttpResponse(stream.getvalue(), content_type="image/png")
|
|
153
|
+
response["Cache-Control"] = "no-store"
|
|
154
|
+
return response
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
Your form-processing view must validate the submitted answer against the stored
|
|
158
|
+
value and enforce challenge expiration, one-time use, and rate limiting. Keep
|
|
159
|
+
the answer on the server; the image response should contain only the image.
|
|
160
|
+
|
|
161
|
+
The original Django site remains in this repository. The distribution includes
|
|
162
|
+
`bengali_captcha` and its original fonts/backgrounds; it does not install the
|
|
163
|
+
site or its settings.
|
|
164
|
+
The separate `gen_captcha_6/7/8` functions in `main/views.py` remain part of that
|
|
165
|
+
site and are not exposed by this library release.
|
|
166
|
+
|
|
167
|
+
## Optional: use your own font or background
|
|
168
|
+
|
|
169
|
+
Skip this section to use the original CAPTCHA styles. Supply `font` or
|
|
170
|
+
`background` only when you want to replace a bundled asset; each override is
|
|
171
|
+
independent, so the asset you do not override keeps its bundled default.
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
from bengali_captcha import BengaliCaptcha
|
|
175
|
+
|
|
176
|
+
# Optional custom font; the background still comes from the package.
|
|
177
|
+
captcha = BengaliCaptcha(variant=2, font="my-bengali-font.ttf")
|
|
178
|
+
|
|
179
|
+
# Optional custom background; the font still comes from the package.
|
|
180
|
+
captcha = BengaliCaptcha(variant=2, background="my-background.png")
|
|
181
|
+
|
|
182
|
+
# Optional: replace both assets.
|
|
183
|
+
captcha = BengaliCaptcha(
|
|
184
|
+
variant=2,
|
|
185
|
+
font="my-bengali-font.ttf",
|
|
186
|
+
background="my-background.png",
|
|
187
|
+
)
|
|
188
|
+
answer, image = captcha.image
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Custom fonts must support Bengali characters. A custom font path or Pillow
|
|
192
|
+
font object works with every variant. Custom backgrounds apply to variants
|
|
193
|
+
2, 3, 5, 6 and 7. Omitting either argument or passing `None` uses its bundled
|
|
194
|
+
default; `background=False` selects a white canvas.
|
|
195
|
+
|
|
196
|
+
The command line also accepts optional overrides:
|
|
197
|
+
|
|
198
|
+
```console
|
|
199
|
+
bengali-captcha captcha.png --variant 2 --font my-bengali-font.ttf --background my-background.png
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
## Scope and limitations
|
|
203
|
+
|
|
204
|
+
- **Character rendering:** The renderers distort individual characters. The
|
|
205
|
+
default alphabet uses standalone Bengali letters and digits. Arbitrary
|
|
206
|
+
Bengali words containing combining marks or conjuncts are not supported as
|
|
207
|
+
shaped text.
|
|
208
|
+
- **Application integration:** This package generates CAPTCHA images. Answer
|
|
209
|
+
validation, expiration, one-time use, and rate limiting belong to the
|
|
210
|
+
integrating application.
|
|
211
|
+
- **Research scope:** The paper evaluates six CAPTCHA variants in its research
|
|
212
|
+
implementation. This package exposes seven renderer APIs; their numbering
|
|
213
|
+
should not be assumed to correspond directly to the paper's evaluated
|
|
214
|
+
variants. The standalone package's resistance to automated solving has not
|
|
215
|
+
been separately evaluated.
|
|
216
|
+
|
|
217
|
+
## Citation
|
|
218
|
+
|
|
219
|
+
If you use **Bengali CAPTCHA** in your research, experiments, or academic
|
|
220
|
+
publications, please cite the following paper:
|
|
221
|
+
|
|
222
|
+
Md Neyamul Islam Shibbir, Md Hasibur Rahman, Farida Chowdhury, and Md Sadek
|
|
223
|
+
Ferdous. **A Usable and Secure Bengali CAPTCHA.** arXiv preprint
|
|
224
|
+
arXiv:2606.29077, 2026.
|
|
225
|
+
|
|
226
|
+
[Read the paper on arXiv](https://arxiv.org/abs/2606.29077).
|
|
227
|
+
|
|
228
|
+
```bibtex
|
|
229
|
+
@article{shibbir2026usable,
|
|
230
|
+
title={A Usable and Secure Bengali CAPTCHA},
|
|
231
|
+
author={Shibbir, Md Neyamul Islam and Rahman, Md Hasibur and Chowdhury, Farida and Ferdous, Md Sadek},
|
|
232
|
+
journal={arXiv preprint arXiv:2606.29077},
|
|
233
|
+
year={2026}
|
|
234
|
+
}
|
|
235
|
+
```
|
|
236
|
+
|
|
237
|
+
## Development and publishing
|
|
238
|
+
|
|
239
|
+
From the repository root, install the package in editable mode:
|
|
240
|
+
|
|
241
|
+
```console
|
|
242
|
+
python -m pip install -e .
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
Install the release tools, run the tests, build the distributions, and check
|
|
246
|
+
the package metadata:
|
|
247
|
+
|
|
248
|
+
```console
|
|
249
|
+
python -m pip install -e ".[release]"
|
|
250
|
+
python -m unittest discover -s tests -v
|
|
251
|
+
python -m build
|
|
252
|
+
python -m twine check --strict dist/*
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## Acknowledgements
|
|
256
|
+
|
|
257
|
+
The generators are loosely derived from
|
|
258
|
+
[Claptcha by Piotr Kuszaj](https://github.com/kuszaj/claptcha).
|
|
259
|
+
Bengali-specific variant changes originate in the `captchaWeb` research application.
|
|
260
|
+
|
|
261
|
+
## License and credits
|
|
262
|
+
|
|
263
|
+
MIT License
|
|
264
|
+
|
|
265
|
+
Copyright (c) 2026 Md Neyamul Islam Shibbir, Md Hasibur Rahman, Md Sadek Ferdous, Farida Chowdhury
|
|
266
|
+
|
|
267
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
268
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
269
|
+
in the Software without restriction, including without limitation the rights
|
|
270
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
271
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
272
|
+
furnished to do so, subject to the following conditions:
|
|
273
|
+
|
|
274
|
+
The above copyright notice and this permission notice shall be included in all
|
|
275
|
+
copies or substantial portions of the Software.
|
|
276
|
+
|
|
277
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
278
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
279
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
280
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
281
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
282
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
283
|
+
SOFTWARE.
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# Bengali CAPTCHA
|
|
2
|
+
|
|
3
|
+
**Generate Bengali (Bangla) CAPTCHA images in Python, with bundled fonts and backgrounds.**
|
|
4
|
+
|
|
5
|
+
`bengali-captcha` is a Pillow-based library for creating image CAPTCHAs with
|
|
6
|
+
Bengali letters and digits. Adapted from the `captchaWeb` research application,
|
|
7
|
+
it provides seven rendering variants through a simple Python API and supports
|
|
8
|
+
Pillow images, in-memory streams, and image files.
|
|
9
|
+
|
|
10
|
+
**The PyPI package includes the original Bengali fonts and background images.**
|
|
11
|
+
Installing it with `pip` installs those assets too. All seven CAPTCHA variants
|
|
12
|
+
select their bundled assets automatically: no font path, background path,
|
|
13
|
+
separate download, or configuration is required.
|
|
14
|
+
|
|
15
|
+
The project is associated with the research paper
|
|
16
|
+
[**A Usable and Secure Bengali CAPTCHA**](https://arxiv.org/abs/2606.29077).
|
|
17
|
+
If you use this library in your research, please cite the paper using the
|
|
18
|
+
BibTeX entry in the **Citation** section below.
|
|
19
|
+
|
|
20
|
+
## Sample CAPTCHA
|
|
21
|
+
|
|
22
|
+
## Sample CAPTCHA
|
|
23
|
+
|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
## Features
|
|
27
|
+
|
|
28
|
+
- Seven rendering variants with automatically selected fonts and backgrounds.
|
|
29
|
+
- Bundled assets for offline generation after installation.
|
|
30
|
+
- Random Bengali challenge text generated using Python's `secrets` module.
|
|
31
|
+
- Custom challenge text, text-source callables, and configurable random-text length.
|
|
32
|
+
- Adjustable image size, margins, noise, and output format.
|
|
33
|
+
- Optional custom fonts, backgrounds, and supported text colors.
|
|
34
|
+
- Pillow image, in-memory stream, and file output.
|
|
35
|
+
- Command-line interface and a Django integration example.
|
|
36
|
+
|
|
37
|
+
## Installation
|
|
38
|
+
|
|
39
|
+
Requires **Python 3.10 or newer**.
|
|
40
|
+
|
|
41
|
+
```console
|
|
42
|
+
python -m pip install bengali-captcha
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Quick start
|
|
46
|
+
|
|
47
|
+
The original Bengali fonts and background images are included. Generate a
|
|
48
|
+
CAPTCHA immediately, with no font downloads or custom image paths:
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from bengali_captcha import BengaliCaptcha
|
|
52
|
+
|
|
53
|
+
captcha = BengaliCaptcha()
|
|
54
|
+
answer, image = captcha.image
|
|
55
|
+
image.save("captcha.png")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
All seven variants work out of the box:
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
for variant in range(1, 8):
|
|
62
|
+
answer, path = BengaliCaptcha(variant=variant).write(f"captcha-{variant}.png")
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
By default, the answer contains four characters from the original project's
|
|
66
|
+
Bengali alphabet and digit selection. Challenge text uses `secrets` randomness.
|
|
67
|
+
Pass `length=5` to change the length, or supply a string or callable as `source`.
|
|
68
|
+
|
|
69
|
+
To generate a longer random challenge:
|
|
70
|
+
|
|
71
|
+
```python
|
|
72
|
+
captcha = BengaliCaptcha(length=5)
|
|
73
|
+
answer, image = captcha.image
|
|
74
|
+
image.save("captcha.png")
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Output options
|
|
78
|
+
|
|
79
|
+
| API | Returns |
|
|
80
|
+
| --- | --- |
|
|
81
|
+
| `captcha.image` | `(answer, image)`, where `image` is a Pillow image |
|
|
82
|
+
| `captcha.bytes` | `(answer, stream)`, where `stream` is a `BytesIO` object positioned at the beginning |
|
|
83
|
+
| `captcha.write("captcha.png")` | `(answer, path)`, after writing a newly generated image to disk |
|
|
84
|
+
|
|
85
|
+
Generate image bytes using the included assets:
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
captcha = BengaliCaptcha(variant=2, source="কখ১২")
|
|
89
|
+
answer, stream = captcha.bytes # BytesIO, positioned at the beginning
|
|
90
|
+
png_data = stream.getvalue()
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
To generate and save directly to a file:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
answer, path = captcha.write("captcha.png")
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
**Each access to `.image`, `.bytes`, or `.write()` creates a new image and calls
|
|
100
|
+
the text source again.** Keep the answer returned by the same call as the image
|
|
101
|
+
you display. To save that exact image, use its `.save()` method as shown in the
|
|
102
|
+
quick start.
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
## Command-line usage
|
|
106
|
+
|
|
107
|
+
```console
|
|
108
|
+
bengali-captcha captcha.png
|
|
109
|
+
bengali-captcha captcha.png --variant 1 --length 4
|
|
110
|
+
python -m bengali_captcha captcha.png --variant 7
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
These commands use the included fonts and images. The only filename required
|
|
114
|
+
is where to save the generated PNG. The command prints its answer in UTF-8.
|
|
115
|
+
|
|
116
|
+
## Django integration
|
|
117
|
+
|
|
118
|
+
Generate bytes for each request and keep the corresponding answer in the
|
|
119
|
+
user's session. For example, inside a Django view:
|
|
120
|
+
|
|
121
|
+
```python
|
|
122
|
+
from django.http import HttpResponse
|
|
123
|
+
from bengali_captcha import BengaliCaptcha
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def captcha_image(request):
|
|
127
|
+
answer, stream = BengaliCaptcha().bytes
|
|
128
|
+
request.session["captcha_answer"] = answer
|
|
129
|
+
response = HttpResponse(stream.getvalue(), content_type="image/png")
|
|
130
|
+
response["Cache-Control"] = "no-store"
|
|
131
|
+
return response
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Your form-processing view must validate the submitted answer against the stored
|
|
135
|
+
value and enforce challenge expiration, one-time use, and rate limiting. Keep
|
|
136
|
+
the answer on the server; the image response should contain only the image.
|
|
137
|
+
|
|
138
|
+
The original Django site remains in this repository. The distribution includes
|
|
139
|
+
`bengali_captcha` and its original fonts/backgrounds; it does not install the
|
|
140
|
+
site or its settings.
|
|
141
|
+
The separate `gen_captcha_6/7/8` functions in `main/views.py` remain part of that
|
|
142
|
+
site and are not exposed by this library release.
|
|
143
|
+
|
|
144
|
+
## Optional: use your own font or background
|
|
145
|
+
|
|
146
|
+
Skip this section to use the original CAPTCHA styles. Supply `font` or
|
|
147
|
+
`background` only when you want to replace a bundled asset; each override is
|
|
148
|
+
independent, so the asset you do not override keeps its bundled default.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
from bengali_captcha import BengaliCaptcha
|
|
152
|
+
|
|
153
|
+
# Optional custom font; the background still comes from the package.
|
|
154
|
+
captcha = BengaliCaptcha(variant=2, font="my-bengali-font.ttf")
|
|
155
|
+
|
|
156
|
+
# Optional custom background; the font still comes from the package.
|
|
157
|
+
captcha = BengaliCaptcha(variant=2, background="my-background.png")
|
|
158
|
+
|
|
159
|
+
# Optional: replace both assets.
|
|
160
|
+
captcha = BengaliCaptcha(
|
|
161
|
+
variant=2,
|
|
162
|
+
font="my-bengali-font.ttf",
|
|
163
|
+
background="my-background.png",
|
|
164
|
+
)
|
|
165
|
+
answer, image = captcha.image
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
Custom fonts must support Bengali characters. A custom font path or Pillow
|
|
169
|
+
font object works with every variant. Custom backgrounds apply to variants
|
|
170
|
+
2, 3, 5, 6 and 7. Omitting either argument or passing `None` uses its bundled
|
|
171
|
+
default; `background=False` selects a white canvas.
|
|
172
|
+
|
|
173
|
+
The command line also accepts optional overrides:
|
|
174
|
+
|
|
175
|
+
```console
|
|
176
|
+
bengali-captcha captcha.png --variant 2 --font my-bengali-font.ttf --background my-background.png
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Scope and limitations
|
|
180
|
+
|
|
181
|
+
- **Character rendering:** The renderers distort individual characters. The
|
|
182
|
+
default alphabet uses standalone Bengali letters and digits. Arbitrary
|
|
183
|
+
Bengali words containing combining marks or conjuncts are not supported as
|
|
184
|
+
shaped text.
|
|
185
|
+
- **Application integration:** This package generates CAPTCHA images. Answer
|
|
186
|
+
validation, expiration, one-time use, and rate limiting belong to the
|
|
187
|
+
integrating application.
|
|
188
|
+
- **Research scope:** The paper evaluates six CAPTCHA variants in its research
|
|
189
|
+
implementation. This package exposes seven renderer APIs; their numbering
|
|
190
|
+
should not be assumed to correspond directly to the paper's evaluated
|
|
191
|
+
variants. The standalone package's resistance to automated solving has not
|
|
192
|
+
been separately evaluated.
|
|
193
|
+
|
|
194
|
+
## Citation
|
|
195
|
+
|
|
196
|
+
If you use **Bengali CAPTCHA** in your research, experiments, or academic
|
|
197
|
+
publications, please cite the following paper:
|
|
198
|
+
|
|
199
|
+
Md Neyamul Islam Shibbir, Md Hasibur Rahman, Farida Chowdhury, and Md Sadek
|
|
200
|
+
Ferdous. **A Usable and Secure Bengali CAPTCHA.** arXiv preprint
|
|
201
|
+
arXiv:2606.29077, 2026.
|
|
202
|
+
|
|
203
|
+
[Read the paper on arXiv](https://arxiv.org/abs/2606.29077).
|
|
204
|
+
|
|
205
|
+
```bibtex
|
|
206
|
+
@article{shibbir2026usable,
|
|
207
|
+
title={A Usable and Secure Bengali CAPTCHA},
|
|
208
|
+
author={Shibbir, Md Neyamul Islam and Rahman, Md Hasibur and Chowdhury, Farida and Ferdous, Md Sadek},
|
|
209
|
+
journal={arXiv preprint arXiv:2606.29077},
|
|
210
|
+
year={2026}
|
|
211
|
+
}
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
## Development and publishing
|
|
215
|
+
|
|
216
|
+
From the repository root, install the package in editable mode:
|
|
217
|
+
|
|
218
|
+
```console
|
|
219
|
+
python -m pip install -e .
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Install the release tools, run the tests, build the distributions, and check
|
|
223
|
+
the package metadata:
|
|
224
|
+
|
|
225
|
+
```console
|
|
226
|
+
python -m pip install -e ".[release]"
|
|
227
|
+
python -m unittest discover -s tests -v
|
|
228
|
+
python -m build
|
|
229
|
+
python -m twine check --strict dist/*
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Acknowledgements
|
|
233
|
+
|
|
234
|
+
The generators are loosely derived from
|
|
235
|
+
[Claptcha by Piotr Kuszaj](https://github.com/kuszaj/claptcha).
|
|
236
|
+
Bengali-specific variant changes originate in the `captchaWeb` research application.
|
|
237
|
+
|
|
238
|
+
## License and credits
|
|
239
|
+
|
|
240
|
+
MIT License
|
|
241
|
+
|
|
242
|
+
Copyright (c) 2026 Md Neyamul Islam Shibbir, Md Hasibur Rahman, Md Sadek Ferdous, Farida Chowdhury
|
|
243
|
+
|
|
244
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
245
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
246
|
+
in the Software without restriction, including without limitation the rights
|
|
247
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
248
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
249
|
+
furnished to do so, subject to the following conditions:
|
|
250
|
+
|
|
251
|
+
The above copyright notice and this permission notice shall be included in all
|
|
252
|
+
copies or substantial portions of the Software.
|
|
253
|
+
|
|
254
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
255
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
256
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
257
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
258
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
259
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
260
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2017 Piotr Kuszaj
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "bengali-captcha"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Seven Bengali CAPTCHA variants with original fonts and backgrounds included"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = "MIT"
|
|
12
|
+
license-files = ["LICENSE", "licenses/*.txt"]
|
|
13
|
+
dependencies = ["Pillow>=10.1"]
|
|
14
|
+
keywords = ["bengali", "bangla", "captcha", "pillow", "image"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Natural Language :: Bengali",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Operating System :: OS Independent",
|
|
21
|
+
"Topic :: Multimedia :: Graphics",
|
|
22
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
23
|
+
]
|
|
24
|
+
|
|
25
|
+
[project.optional-dependencies]
|
|
26
|
+
release = ["build>=1.2", "twine>=6"]
|
|
27
|
+
|
|
28
|
+
[project.scripts]
|
|
29
|
+
bengali-captcha = "bengali_captcha.__main__:main"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["src"]
|
|
33
|
+
include = ["bengali_captcha*"]
|
|
34
|
+
namespaces = false
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
include-package-data = false
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.package-data]
|
|
40
|
+
bengali_captcha = ["assets/fonts/*.ttf", "assets/backgrounds/*.png", "assets/backgrounds/*.jpg"]
|