Skip to main content

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

Project description

Install

Install from pypi pip install flask-simple-captcha-k-fork Install from source python3 setup.py install

How to use

This package is intended to assign a unique CSRF string per each form submit per user session, without requiring any backend session tracking. First, you'll want to set a variable CAPTCHA_CONFIG['SECRET_CAPTCHA_KEY'] in your app config to a random, complex string. Example: CAPTCHA_CONFIG = {'SECRET_CAPTCHA_KEY':'wMmeltW4mhwidorQRli6Oijuhygtfgybunxx9VPXldz'}

Second, add this to the top of your code.

from flask_simple_captcha import CAPTCHA


CAPTCHA = CAPTCHA(config=config.CAPTCHA_CONFIG)
app = CAPTCHA.init_app(app)

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

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

    if request.method == 'GET':
        captcha = CAPTCHA.create()
        return render_template('example.html', captcha=captcha)

In the HTML forms you want to generate a captcha: {{ captcha_html(captcha) }}

This will create something like this:

<input type="text" name="captcha-text">
<input type="hidden" name="captcha-hash" value="1o9ig...">

To make a customized-size captcha, you can do:

captcha = CAPTCHA.create(length=10, digits=True)

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-k-fork-1.1.2.tar.gz (204.5 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file flask-simple-captcha-k-fork-1.1.2.tar.gz.

File metadata

File hashes

Hashes for flask-simple-captcha-k-fork-1.1.2.tar.gz
Algorithm Hash digest
SHA256 375c76d545b230fb0bea8b611cdc2891c896169d245405ebce6f48d228c9bb49
MD5 be92270114ad7fcba62cef890fb3d67a
BLAKE2b-256 cb88f2fbc5c34c9f03ba9e3420ba167b21bf7ba1ea5bcd4fd3fb7431c4de0c18

See more details on using hashes here.

File details

Details for the file flask_simple_captcha_k_fork-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_simple_captcha_k_fork-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8ff1e155db78b345d65bc5856b5295cd51160f00f531fbe7ad2e9ae2c85ae32e
MD5 fef19227becc2bc4391af9a008c51347
BLAKE2b-256 2218b5b231c4230c73081ef5a7997781407d8476f814fd5e4baa2d80beabdd01

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