Skip to main content

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

Project description

Install

pip3 install flask-simple-captcha or if installing 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 == '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 CAPTCHA.verify(c_text, c_hash):
            return 'success'
        else:
            return 'failed 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...">

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-r-1.1.0.tar.gz (204.2 kB view details)

Uploaded Source

File details

Details for the file flask-simple-captcha-r-1.1.0.tar.gz.

File metadata

  • Download URL: flask-simple-captcha-r-1.1.0.tar.gz
  • Upload date:
  • Size: 204.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.4

File hashes

Hashes for flask-simple-captcha-r-1.1.0.tar.gz
Algorithm Hash digest
SHA256 7c0005e1f6b8daec2705c273addad5eb5d42c26929610c7112765b441c62b4bb
MD5 9967f9ebb46160ac980d3a91c6b5d794
BLAKE2b-256 5ac6a182eca76e5f4aee6601551410764022059b55fc31052208b4e349365349

See more details on using hashes here.

Supported by

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