Skip to main content

DisCapTy help you generate obfuscated images, leaving your code easy.

Project description

DisCapTy

DisCapTy's LogoDisCapTy's Logo

DisCapTy is a highly type hinted Python module to generate Captcha images without struggling your mind on how to make your own. Everyone can use it!

Documentation: https://discapty.readthedocs.io/

Installing

DisCapTy is available on PyPi!

pip3 install discapty

To use DisCapTy, you need a Python version equal or greater to 3.7 and below 3.11.

Clone & Test the project

This project is dependant of Poetry, a dependency management tool. You are most likely going to require this tool to correctly interact with the project & its dependencies, check out Poetry's documentation for how to install it.

To clone the repository: git clone https://github.com/Predeactor/DisCapTy.git

To install dependencies: poetry install

To run tests: poetry run python -m unittest

Creating Captcha

For DisCapTy, a Captcha is simply a code with any possible objects that can be returned, for example, it is one code (Like "12345") with an image (Usually a PIL.Image.Image object) This is because DisCapTy uses the concept of generators that are used to generate a captcha from a given code, and it can return anything.

DisCapTy comes with 3 builtin generators:

  • TextGenerator : Text based captcha
  • WheezyGenerator : Image based captcha
  • ImageGenerator : Image based captcha

Creating Captcha manually

import discapty

def generate_a_captcha(initial_input: str) -> discapty.Captcha:
    # This generator returns an obfuscated text.
    captcha_for_user = discapty.TextGenerator().generate(initial_input)
    # Create a Captcha object, the first argument is the clear code, the second is the obfuscated code. Anything goes.
    return discapty.Captcha(initial_input, captcha_for_user)

# Generate your Captcha.
captcha = generate_a_captcha("12345")

# Show the obfuscated code. See https://discapty.readthedocs.io for more information on this object.
show_captcha_to_user(captcha.captcha)

Checking user's input

import discapty

# Generate your Captcha.
captcha: discapty.Captcha = generate_a_captcha("12345")

# This is your user's input here
user_input: str = '12345'

if captcha.check(user_input) is True:
    # The user input is correct
    print("Correct!")
else:
    # The user input is incorrect
    print("Incorrect!")

What's great with the .check method is that you can specify if you need to remove space in the user's input and/or check casing.

Creating Captcha manually is not a recommended way, because DisCapTy comes with its opinionated challenge runner & is inefficient anyway.

Create a Challenge

import discapty

challenge = discapty.Challenge(discapty.TextGenerator(), retries=3)

captcha = challenge.begin()

# We cannot provide typehint here, `captcha` is a `typing.Any` and cannot help you, it'll be your
# job to know what you'll get as a captcha.
send_captcha_to_user(captcha)
user_input: str = get_user_input()

is_correct: bool = challenge.check(user_input)
# If the user's input is correct, the challenge ends, if not, `challenge.attempted_tries` will get
# +1, and if it is greater than the retries that has been set, then an error is raised when using
# `.check`

Please see the documentation for more information on how the library work.

Contact

You can join my Discord server for any help: https://discord.gg/aPVupKAxxP

DisCapTy is an open-source project distributed under the MIT license: PyPI - License

DisCapTy uses the Roboto font as default font. This font is licensed under Apache-2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

discapty-2.1.2.tar.gz (109.6 kB view details)

Uploaded Source

Built Distribution

discapty-2.1.2-py3-none-any.whl (109.1 kB view details)

Uploaded Python 3

File details

Details for the file discapty-2.1.2.tar.gz.

File metadata

  • Download URL: discapty-2.1.2.tar.gz
  • Upload date:
  • Size: 109.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

File hashes

Hashes for discapty-2.1.2.tar.gz
Algorithm Hash digest
SHA256 b19afcc8f376343d211b56c79285d0049b371ec8a0fa637230c97fee67106c35
MD5 06bde1a1cc73c1f4ea9df92352b48f0b
BLAKE2b-256 9c92b99b5776af836e590f4cc62dcc1d1f76e6688ee8a92bb910d75e4be4691a

See more details on using hashes here.

File details

Details for the file discapty-2.1.2-py3-none-any.whl.

File metadata

  • Download URL: discapty-2.1.2-py3-none-any.whl
  • Upload date:
  • Size: 109.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.2 CPython/3.10.6 Linux/5.15.0-1031-azure

File hashes

Hashes for discapty-2.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 95909a1f765b33b1fb98a50d54f24af885d60ff36c051578773a3f15d32f9a72
MD5 1b97798b798d21f69364baa9ddda5dd4
BLAKE2b-256 4ba735c7022d1a0c24218398795e9d54bee34c4db7edb06a8fdfe93cbf789659

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page