Captcha implementation for flask and flask-session.
Project description
A captcha implemention for flask using flask-session and captcha packages. Each captcha challenge answer is saved in the server side session of the challenged client.
For now it supports only simple numeric image captchas, but more could easily be added from the underlying captcha package.
Requirements
flask-session with packages depending on which SESSION_TYPE you use. E.g. sqlalchemy requires flask-sqlalchemy.
Usage
import uuid
import logging
from flask import Flask, request, render_template
from flask_session import Session
from flask_session_captcha import FlaskSessionCaptcha
app = Flask(__name__)
app.config["SECRET_KEY"] = uuid.uuid4()
app.config['CAPTCHA_ENABLE'] = True
app.config['CAPTCHA_NUMERIC_DIGITS'] = 5
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite://'
app.config['SESSION_TYPE'] = 'sqlalchemy'
Session(app)
captcha = FlaskSessionCaptcha(app)
@app.route('/', methods=['POST','GET'])
def some_route():
if request.method == "POST":
if captcha.validate():
return "success"
else:
return "fail"
return render_template("form.html")
if __name__ == "__main__":
app.debug = True
logging.getLogger().setLevel("DEBUG")
app.run()
Template can look as follows. captcha.validate() will be default try to validate against a form input with name “captcha”.
<form method="POST">
{{ captcha() }} <!-- This renders an <img> tag with the captcha img. -->
<input type="text" name="captcha">
<input type="submit">
</form>
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 Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
Close
Hashes for flask_session_captcha-1.0.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7cc5740e83bff49120a6d6f1e57ea503fd045736f1c6402c215037831f0880d1 |
|
MD5 | f3233abf1d8db66b55a274b37984cad7 |
|
BLAKE2b-256 | 3c301e2b000b88b162b6e168c1abec47235fc8cef1b5d2af2da8ae4b4d339250 |