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_CSRF_KEY']
in your app config to a random, complex string. Example: CAPTCHA_CONFIG = {'SECRET_CSRF_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
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
Built Distribution
Hashes for flask-simple-captcha-1.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b828095fb497d873442fc075f4690c67aa0792c2a4641c668f4ba57f50233d5 |
|
MD5 | c6e8e4ddddecc52247d9451404762f22 |
|
BLAKE2b-256 | 8d72ed70015e8381911e35a5e0e36da73f8578548fb75863906a1e35e5398458 |
Hashes for flask_simple_captcha-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 722806a5e12974dd2b8dcd6cc0877900fd3164090323c8e620bebaa485f36c25 |
|
MD5 | 7c4163ad2703467e7dda1333f5ce1922 |
|
BLAKE2b-256 | bd24f215ce6178f7bfdfa786758898732d0b60604311a1562153a5f63aa80cf9 |