flask captcha2
===============
<img src="https://github.com/alisharify7/flask_captcha2/blob/main/docs/flask-captcha2-black.png?raw=true">
Flask plugin to integrate Google-captcha (version 2, 3) and local
captcha (image, voice) with Flask applications
<a href="https://www.coffeete.ir/alisharify7">Donate/Support [Optional]</a>
<img alt="GitHub repo size" src="https://img.shields.io/github/repo-size/alisharify7/flask_captcha2"> <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/alisharify7/flask_captcha2"> <img alt="GitHub repo Licence" src="https://img.shields.io/pypi/l/flask_captcha2">
[![Latest version](https://img.shields.io/pypi/v/Flask-captcha2)](https://pypi.python.org/pypi/Flask-captcha2)[![Supported python versions](https://img.shields.io/pypi/pyversions/Flask-captcha2)](https://pypi.python.org/pypi/flask_captcha2) [![Downloads](https://static.pepy.tech/badge/flask-captcha2)](https://pepy.tech/project/flask-captcha2) [![Downloads](https://static.pepy.tech/badge/flask-captcha2/month)](https://pepy.tech/project/flask-captcha2)
0.0 how to install:
-------------------
``` {.}
pip install -U flask_captcha2
```
0.1 how to use:
---------------
```python
from flask import Flask
from flask_captcha2 import FlaskCaptcha
app = Flask(__name__)
google_captcha2_config_list = {
"CAPTCHA_PRIVATE_KEY": "hish !",
"CAPTCHA_PUBLIC_KEY": "hish !",
'CAPTCHA_ENABLED': True, # captcha status <True, False>
"CAPTCHA_LOG": True, # show captcha logs in console
"CAPTCHA_LANGUAGE": "en" # captcha language
}
google_captcha3_config_list = {
"CAPTCHA_PRIVATE_KEY": "hish !",
"CAPTCHA_PUBLIC_KEY": "hish !",
'CAPTCHA_ENABLED': True, # captcha status <True, False>
"CAPTCHA_SCORE": 0.5, #google captcha version3 works with scores
"CAPTCHA_LOG": True # show captcha requests and logs in terminal > stdout
}
MainCaptcha = FlaskCaptcha(app=app) # app is required
# passing config list directly
google_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2', conf=google_captcha2_config_list)
google_captcha3 = MainCaptcha.get_google_captcha_v3(name='g-captcha3', conf=google_captcha3_config_list)
# Namespaces are important. Do not use repeated names and choose names with meaning.
```
google captcha docs
https://developers.google.com/recaptcha/docs/v3
## example:
```python
# you can also pass nothing and it will be uses app.config for filling configs
app.config.update(google_captcha3_config_list) # set configs in app.config
MainCaptcha = FlaskCaptcha(app=app)
# No need to send conf_list, it will be set automatically from app.config
google_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2')
```
0.2 how use in templates for rendering Captcha Widget:
------------------------------------------------------
#### Use < captcha.render_captcha > Filter to render a captcha in html
##### -> Remember namespaces argument in crating a captcha object
```python
google_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2') # name
google_captcha3 = MainCaptcha.get_google_captcha_v3(name='g-captcha3') # name
```
for rendering a captcha width you should pass name to < model_name > in < captcha.render_captcha >
## rendering Google Version 2 Captcha:
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Captcha version 2</title>
</head>
<body>
<form method="POST" action="some-url">
<input placeholder="username" type="text" name="username" id="">
<br>
<input placeholder="password" type="password" name="password" id="">
<br>
<input value="submit" type="submit">
{#
all available parameter for google captcha version 2:
model_name: required,
id: optional,
css_class: optional,
inline_css: optional,
js_event: optional,
dataset: optional,
#}
{{
captcha.render_captcha (
# [Required] namespace
model_name='g-captcha2',
# [Optional] add id to captcha widget
id='g-captcha-v2',
# [Optional] add css class to captcha widget
css_class='p-2 btn btn-primary',
# [Optional] add inline css to captcha widget
inline_css='font-size:10px;',
# [Optional] add dataset to captcha widget
dataset="data-checked='true';"
# [Optional] add js event to captcha widget
js_event="onclick(alert('clicked!'))",
)
}}
</form>
</body>
</html>
```
## Google captcha version 2 `render` parameters
| parameter | description | type | status |
|------------|----------------------------------|------|------------|
| model_name | namespace | str | `Required` |
| id | id of captcha widget in html | str | `Optional` |
| css_class | add css class to captcha widget | str | `Optional` |
| inline_css | add inline css to captcha widget | str | `Optional` |
| dataset | add dataset to captcha widget | str | `Optional` |
| js_event | add js event to captcha widget | str | `Optional` |
## rendering Google Version 3 Captcha :
```html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Captcha version 3</title>
</head>
<body>
<form method="POST" action="/v3" id="ParentForm"> # <---- parent_form_id
{# you can also use Flask-wtf forms #}
<input placeholder="username" type="text" name="username" id="">
<br>
<input placeholder="password" type="password" name="password" id="">
<br>
{{
captcha.render_captcha (
# [Required] Namespace
model_name='g-captcha3'
# [Optional] add id to captcha widget
id="SubmitBtnForm"
# [Optional] add custom css class to captcha widget
css_class='custom-class-name'
# [Optional] inline css of captcha widget
inline_css="background-color:blue; color:white; font-size:2rem;"
# [Optional] add dataset to captcha widget
dataset="data-ok='true' data-test='test data set check' "
# [Required] if of parent form
parent_form_id="ParentForm"
# [Required] text content of the submit button
button_text="submit This Form"
# [Optional] javascript event of captcha widget
js_event="onclick='alert('this is inline event');' "
# [Optional] set visibility of captcha widget in bottom right corner,
# this parameter doesn't disable captcha, its only hidden the captcha in
# the page, but captcha still works
hide_badge=True
)
}}
</form>
</body>
</html>
```
## Google captcha version 3 `render` parameters
| parameter | description | type | status |
|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------------|
| model_name | namespace | str | `Required` |
| id | id of captcha widget in html | str | `Optional` |
| css_class | add css class to captcha widget | str | `Optional` |
| inline_css | add inline css to captcha widget | str | `Optional` |
| dataset | add dataset to captcha widget | str | `Optional` |
| js_event | add js event to captcha widget | str | `Optional` |
| parent_form_id | id of parent form element | str | `Required` |
| hide_badge | set visibility of captcha widget in bottom right corner, this parameter doesn't disable captcha, its only hidden the captcha in the page, but captcha still works | str | `Optional` |
| button_text | text context of the captcha button | str | `Required` |
0.3 How to verify Captcha:
-----------------------
Use the is_verify method on captcha objects for validating a request that
contains a captcha
```python
@app.route("/g-v2-verify/", methods=["POST"])
def index():
# with is_verify method verify the captcha
if google_captcha2.is_verify():
return "Captcha is ok."
else:
return "Try again!"
@app.route("/g-v3-verify/", methods=["POST"])
def index():
# with the is_verify method verify the captcha
if google_captcha3.is_verify():
return "Captcha is ok."
else:
return "Try again!"
```
### Version History:
- version 2.0.0 Released: May 18, 2023
- Changes: - None
- version 2.0.1 Released: June 9, 2023
- Changes:
> - Change FlaskCaptcha Class to FlaskCaptcha2
> - Fix bug in rendering captcha widget when captcha-enable was False
- version 3.0.0 Released: September 9, 2023
- Changes:
> - Change package structure
> - Add Captcha version 3 and fix some bugs in Captcha version 2
- version 3.0.4 Released: October 27, 2023
- Changes:
> - reformat/Refactor project structure
> - adding FlaskCaptcha Master class
> - adding getFlaskCaptcha3 method for getting google-captcha
> version 3
> - adding getFlaskCaptcha2 method for getting google-captcha version 2
> - adding namespacing for each captcha
> - adding the ability to create multiple captchas with different versions
> - adding pytest base test
- version 3.0.5 Released: July 21, 2024
- Changes:
> - reformat/Refactor code
> - rename render_captcha parameters
- version 3.1.0 Released: September 28, 2024
- Changes:
> - reformat/Refactor code
> - Refactoring all method and function signatures to adhere to PEP8 input parameter naming conventions.
> - minor changes.
Raw data
{
"_id": null,
"home_page": "https://github.com/alisharify7/flask_captcha2",
"name": "Flask-captcha2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "flask security, Google captcha for flask, captcha, flask, flask-captcha, flask-captcha2, flask_captcha2, flask-images-captcha",
"author": "ali sharify",
"author_email": "alisharifyofficial@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/4f/b8/6d7467cf080e3e78090c3cbd3f41eee59d5ea2b9fe1cdc40097343453fcc/flask_captcha2-3.1.0.tar.gz",
"platform": null,
"description": "flask captcha2\r\n===============\r\n\r\n<img src=\"https://github.com/alisharify7/flask_captcha2/blob/main/docs/flask-captcha2-black.png?raw=true\">\r\n\r\nFlask plugin to integrate Google-captcha (version 2, 3) and local\r\ncaptcha (image, voice) with Flask applications\r\n\r\n<a href=\"https://www.coffeete.ir/alisharify7\">Donate/Support [Optional]</a>\r\n\r\n<img alt=\"GitHub repo size\" src=\"https://img.shields.io/github/repo-size/alisharify7/flask_captcha2\"> <img alt=\"GitHub contributors\" src=\"https://img.shields.io/github/contributors/alisharify7/flask_captcha2\"> <img alt=\"GitHub repo Licence\" src=\"https://img.shields.io/pypi/l/flask_captcha2\">\r\n\r\n[![Latest version](https://img.shields.io/pypi/v/Flask-captcha2)](https://pypi.python.org/pypi/Flask-captcha2)[![Supported python versions](https://img.shields.io/pypi/pyversions/Flask-captcha2)](https://pypi.python.org/pypi/flask_captcha2) [![Downloads](https://static.pepy.tech/badge/flask-captcha2)](https://pepy.tech/project/flask-captcha2) [![Downloads](https://static.pepy.tech/badge/flask-captcha2/month)](https://pepy.tech/project/flask-captcha2)\r\n \r\n\r\n0.0 how to install:\r\n-------------------\r\n\r\n``` {.}\r\npip install -U flask_captcha2 \r\n```\r\n\r\n0.1 how to use:\r\n---------------\r\n\r\n```python\r\nfrom flask import Flask\r\nfrom flask_captcha2 import FlaskCaptcha\r\n\r\napp = Flask(__name__)\r\n\r\n\r\n google_captcha2_config_list = {\r\n \"CAPTCHA_PRIVATE_KEY\": \"hish !\",\r\n \"CAPTCHA_PUBLIC_KEY\": \"hish !\",\r\n 'CAPTCHA_ENABLED': True, # captcha status <True, False> \r\n \"CAPTCHA_LOG\": True, # show captcha logs in console\r\n \"CAPTCHA_LANGUAGE\": \"en\" # captcha language\r\n }\r\n\r\n google_captcha3_config_list = {\r\n \"CAPTCHA_PRIVATE_KEY\": \"hish !\",\r\n \"CAPTCHA_PUBLIC_KEY\": \"hish !\",\r\n 'CAPTCHA_ENABLED': True, # captcha status <True, False> \r\n \"CAPTCHA_SCORE\": 0.5, #google captcha version3 works with scores\r\n \"CAPTCHA_LOG\": True # show captcha requests and logs in terminal > stdout\r\n }\r\n\r\n MainCaptcha = FlaskCaptcha(app=app) # app is required\r\n # passing config list directly\r\n google_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2', conf=google_captcha2_config_list)\r\n google_captcha3 = MainCaptcha.get_google_captcha_v3(name='g-captcha3', conf=google_captcha3_config_list)\r\n # Namespaces are important. Do not use repeated names and choose names with meaning.\r\n```\r\n\r\ngoogle captcha docs\r\nhttps://developers.google.com/recaptcha/docs/v3\r\n## example:\r\n\r\n```python\r\n# you can also pass nothing and it will be uses app.config for filling configs\r\n app.config.update(google_captcha3_config_list) # set configs in app.config\r\n MainCaptcha = FlaskCaptcha(app=app)\r\n # No need to send conf_list, it will be set automatically from app.config\r\n google_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2')\r\n```\r\n\r\n0.2 how use in templates for rendering Captcha Widget:\r\n------------------------------------------------------\r\n\r\n#### Use < captcha.render_captcha > Filter to render a captcha in html\r\n\r\n##### -> Remember namespaces argument in crating a captcha object\r\n\r\n```python\r\ngoogle_captcha2 = MainCaptcha.get_google_captcha_v2(name='g-captcha2') # name\r\ngoogle_captcha3 = MainCaptcha.get_google_captcha_v3(name='g-captcha3') # name\r\n```\r\n\r\nfor rendering a captcha width you should pass name to < model_name > in < captcha.render_captcha >\r\n\r\n## rendering Google Version 2 Captcha:\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>Captcha version 2</title>\r\n</head>\r\n<body>\r\n\r\n <form method=\"POST\" action=\"some-url\">\r\n <input placeholder=\"username\" type=\"text\" name=\"username\" id=\"\">\r\n <br>\r\n <input placeholder=\"password\" type=\"password\" name=\"password\" id=\"\">\r\n <br>\r\n <input value=\"submit\" type=\"submit\">\r\n\r\n {# \r\n all available parameter for google captcha version 2:\r\n model_name: required,\r\n id: optional,\r\n css_class: optional,\r\n inline_css: optional,\r\n js_event: optional,\r\n dataset: optional,\r\n #}\r\n \r\n \r\n {{\r\n captcha.render_captcha (\r\n # [Required] namespace\r\n model_name='g-captcha2', \r\n \r\n # [Optional] add id to captcha widget\r\n id='g-captcha-v2',\r\n \r\n # [Optional] add css class to captcha widget\r\n css_class='p-2 btn btn-primary',\r\n \r\n # [Optional] add inline css to captcha widget\r\n inline_css='font-size:10px;', \r\n \r\n # [Optional] add dataset to captcha widget\r\n dataset=\"data-checked='true';\"\r\n \r\n # [Optional] add js event to captcha widget\r\n js_event=\"onclick(alert('clicked!'))\", \r\n )\r\n }}\r\n\r\n </form>\r\n</body>\r\n</html>\r\n```\r\n\r\n## Google captcha version 2 `render` parameters\r\n\r\n| parameter | description | type | status | \r\n|------------|----------------------------------|------|------------|\r\n| model_name | namespace | str | `Required` |\r\n| id | id of captcha widget in html | str | `Optional` |\r\n| css_class | add css class to captcha widget | str | `Optional` |\r\n| inline_css | add inline css to captcha widget | str | `Optional` |\r\n| dataset | add dataset to captcha widget | str | `Optional` |\r\n| js_event | add js event to captcha widget | str | `Optional` |\r\n\r\n## rendering Google Version 3 Captcha :\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html lang=\"en\">\r\n<head>\r\n <meta charset=\"UTF-8\">\r\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\">\r\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\r\n <title>Captcha version 3</title>\r\n</head>\r\n<body>\r\n\r\n <form method=\"POST\" action=\"/v3\" id=\"ParentForm\"> # <---- parent_form_id \r\n\r\n{# you can also use Flask-wtf forms #}\r\n <input placeholder=\"username\" type=\"text\" name=\"username\" id=\"\">\r\n <br>\r\n <input placeholder=\"password\" type=\"password\" name=\"password\" id=\"\">\r\n <br>\r\n {{\r\n captcha.render_captcha (\r\n # [Required] Namespace\r\n model_name='g-captcha3'\r\n\r\n # [Optional] add id to captcha widget\r\n id=\"SubmitBtnForm\"\r\n\r\n # [Optional] add custom css class to captcha widget\r\n css_class='custom-class-name'\r\n\r\n # [Optional] inline css of captcha widget\r\n inline_css=\"background-color:blue; color:white; font-size:2rem;\"\r\n\r\n # [Optional] add dataset to captcha widget\r\n dataset=\"data-ok='true' data-test='test data set check' \"\r\n\r\n # [Required] if of parent form\r\n parent_form_id=\"ParentForm\"\r\n\r\n # [Required] text content of the submit button\r\n button_text=\"submit This Form\"\r\n\r\n # [Optional] javascript event of captcha widget\r\n js_event=\"onclick='alert('this is inline event');' \"\r\n\r\n # [Optional] set visibility of captcha widget in bottom right corner,\r\n # this parameter doesn't disable captcha, its only hidden the captcha in\r\n # the page, but captcha still works\r\n hide_badge=True\r\n )\r\n }}\r\n </form>\r\n</body>\r\n</html>\r\n```\r\n\r\n## Google captcha version 3 `render` parameters\r\n\r\n| parameter | description | type | status | \r\n|----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------|------|------------|\r\n| model_name | namespace | str | `Required` |\r\n| id | id of captcha widget in html | str | `Optional` |\r\n| css_class | add css class to captcha widget | str | `Optional` |\r\n| inline_css | add inline css to captcha widget | str | `Optional` |\r\n| dataset | add dataset to captcha widget | str | `Optional` |\r\n| js_event | add js event to captcha widget | str | `Optional` |\r\n| parent_form_id | id of parent form element | str | `Required` |\r\n| hide_badge | set visibility of captcha widget in bottom right corner, this parameter doesn't disable captcha, its only hidden the captcha in the page, but captcha still works | str | `Optional` |\r\n| button_text | text context of the captcha button | str | `Required` |\r\n\r\n0.3 How to verify Captcha:\r\n-----------------------\r\n\r\nUse the is_verify method on captcha objects for validating a request that\r\ncontains a captcha \r\n\r\n```python\r\n@app.route(\"/g-v2-verify/\", methods=[\"POST\"])\r\ndef index():\r\n # with is_verify method verify the captcha \r\n if google_captcha2.is_verify():\r\n return \"Captcha is ok.\"\r\n else:\r\n return \"Try again!\"\r\n\r\n@app.route(\"/g-v3-verify/\", methods=[\"POST\"])\r\ndef index():\r\n # with the is_verify method verify the captcha\r\n if google_captcha3.is_verify():\r\n return \"Captcha is ok.\"\r\n else:\r\n return \"Try again!\"\r\n```\r\n\r\n### Version History:\r\n\r\n- version 2.0.0 Released: May 18, 2023\r\n\r\n- Changes: - None\r\n\r\n- version 2.0.1 Released: June 9, 2023\r\n\r\n- Changes:\r\n\r\n > - Change FlaskCaptcha Class to FlaskCaptcha2\r\n > - Fix bug in rendering captcha widget when captcha-enable was False\r\n\r\n- version 3.0.0 Released: September 9, 2023\r\n\r\n- Changes:\r\n\r\n > - Change package structure\r\n > - Add Captcha version 3 and fix some bugs in Captcha version 2\r\n\r\n- version 3.0.4 Released: October 27, 2023\r\n- Changes:\r\n\r\n > - reformat/Refactor project structure\r\n > - adding FlaskCaptcha Master class\r\n > - adding getFlaskCaptcha3 method for getting google-captcha\r\n > version 3\r\n > - adding getFlaskCaptcha2 method for getting google-captcha version 2\r\n > - adding namespacing for each captcha\r\n > - adding the ability to create multiple captchas with different versions\r\n > - adding pytest base test\r\n\r\n \r\n- version 3.0.5 Released: July 21, 2024\r\n- Changes:\r\n\r\n > - reformat/Refactor code\r\n > - rename render_captcha parameters\r\n \r\n- version 3.1.0 Released: September 28, 2024\r\n- Changes:\r\n\r\n > - reformat/Refactor code\r\n > - Refactoring all method and function signatures to adhere to PEP8 input parameter naming conventions.\r\n > - minor changes.\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Flask plugin to integrate Google captcha (version 2, 3) and local captcha (image, voice) with Flask applications",
"version": "3.1.0",
"project_urls": {
"Homepage": "https://github.com/alisharify7/flask_captcha2"
},
"split_keywords": [
"flask security",
" google captcha for flask",
" captcha",
" flask",
" flask-captcha",
" flask-captcha2",
" flask_captcha2",
" flask-images-captcha"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "10179f0f013b8ac106fc32a96181100f924d0987207fecb22fe1ec42d22ca6d5",
"md5": "48cf8ebb258d50ea1dd9d284a6c5e45a",
"sha256": "b4eaafbf4968a29d61d71c5b0b5e15429f0f40df4f8722989f813f1b3bb71606"
},
"downloads": -1,
"filename": "Flask_captcha2-3.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "48cf8ebb258d50ea1dd9d284a6c5e45a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 20288,
"upload_time": "2024-09-28T16:52:30",
"upload_time_iso_8601": "2024-09-28T16:52:30.652164Z",
"url": "https://files.pythonhosted.org/packages/10/17/9f0f013b8ac106fc32a96181100f924d0987207fecb22fe1ec42d22ca6d5/Flask_captcha2-3.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "4fb86d7467cf080e3e78090c3cbd3f41eee59d5ea2b9fe1cdc40097343453fcc",
"md5": "7611c23e18222c0e6daadb8227f670d1",
"sha256": "9193088d7438579da25da47fa2a630dde136aff0d9626955d99a4fcbdcdd768f"
},
"downloads": -1,
"filename": "flask_captcha2-3.1.0.tar.gz",
"has_sig": false,
"md5_digest": "7611c23e18222c0e6daadb8227f670d1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 14988,
"upload_time": "2024-09-28T16:52:32",
"upload_time_iso_8601": "2024-09-28T16:52:32.778270Z",
"url": "https://files.pythonhosted.org/packages/4f/b8/6d7467cf080e3e78090c3cbd3f41eee59d5ea2b9fe1cdc40097343453fcc/flask_captcha2-3.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-09-28 16:52:32",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "alisharify7",
"github_project": "flask_captcha2",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "flask-captcha2"
}