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
- Install the development requirements:
pip install -r requirements_dev.txt
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for flask-simple-captcha-3.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 602a233e39e1fc3b2f1ac1d7fb7817dc97a3492bf8f21d66024ace0b311d6516 |
|
MD5 | a083978aed3e30617abc8b9028b5402b |
|
BLAKE2b-256 | 2a88298b1cfe7b080afe6087cc05022c3d6e167937736f5b461bcab76b05bb42 |