Skip to main content

Extremely simple, "Good Enough" captcha implemention for flask forms. No server side sessions required.

Reason this release was yanked:

use 4.0 or 1.0

Project description

flask-simple-captcha

CURRENT VERSION: v3.0.0

flask-simple-captcha is a robust CAPTCHA generator class that allows for the creation and verification of CAPTCHAs. This class allows for easy integration into various Flask applications. This library leverages Pillow for image rendering and UUID for unique identification.

Features

  • Generates CAPTCHAs with customizable length and characters
  • Easy integration with various Flask applications
  • Built-in image rendering and line drawing for added complexity
  • Base64 image encoding for easy embedding
  • JWT-based verification for secure CAPTCHA checks
  • Does not require server-side sessions
  • Backwards compatible with 1.0 versions of this package

Prerequisites

  • Python 3.7 or higher
  • Pillow library for image manipulation

Installation

You can use this package by directly importing it into your Flask project. Ensure that all dependencies are installed in your environment.

How to Use

Initialization

Add this to the top of your code:

from flask_simple_captcha import CAPTCHA
SIMPLE_CAPTCHA = CAPTCHA(config=config.CAPTCHA_CONFIG)
app = SIMPLE_CAPTCHA.init_app(app)

Protecting a Route

For each route you want captcha protected, add the following code:

@app.route('/example', methods=['GET','POST'])
def example():
    if request.method == 'GET':
        captcha = CAPTCHA.create()
        render_template('example.html', captcha=captcha)
    if request.method == 'POST':
        c_hash = request.form.get('captcha-hash')
        c_text = request.form.get('captcha-text')
        if SIMPLE_CAPTCHA.verify(c_text, c_hash):
            return 'success'
        else:
            return 'failed captcha'

In the HTML forms, use:

<!-- your_template.html -->
<div class="captcha-container">{{ captcha_html|safe }}</div>

License

MIT


Running Tests

  1. Install the development requirements:
pip install -r requirements_dev.txt
  1. Run the tests:
python3 tests.py

Contributing

Just open a PR. This project was abandoned for years, but as of these most recent commits, has actual quality code but I sunk a weekend into it.

License

MIT

ccarterdev@gmail.com contact me if you think you will pay me more than i'm being paid currently

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

flask-simple-captcha-3.0.0.tar.gz (206.3 kB view hashes)

Uploaded Source

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