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_k_fork 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
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-k-fork-1.1.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a1299abddec8ced01e5f86ea6be5a576736320abef9ca6ab4aad7ec96ea66974 |
|
MD5 | ff4ea5ef0722e002e86f852029fd1498 |
|
BLAKE2b-256 | f196d0ad6033bb2aaf0a11d67cecf7fc1794be39bd9004737b9a0ed8511d7d7f |
Hashes for flask_simple_captcha_k_fork-1.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc6133e4f9c90e84575917ef1aae1c5942bb8a9b5aa2eb3aac982568032dfa63 |
|
MD5 | d77576d980b6a85528e59001fafce45a |
|
BLAKE2b-256 | 6a7bd5c3c3effcb23aaac980b7acf0ef4121411f624383e826d81f8e405fa948 |