common captcha for web server
Project description
common-captcha 验证码程序,包括简单验证码和滑块验证码,基于用户行为验证
Features
简单验证码
滑动拼图验证码
Introduction
Install with pip:
$ pip install common-captcha
Preview
滑块验证码
https://github.com/Asamusummer/common_captcha/blob/main/%E6%BB%91%E5%8A%A8%E6%8B%BC%E5%9B%BE.gif
点击文字验证
https://github.com/Asamusummer/common_captcha/blob/main/%E7%82%B9%E9%80%89%E6%96%87%E5%AD%97.gif
How To Use?
在此之前,你需要准备一个可用的redis
redis_url redis://xxxxxx:xxxxxx@xxxxx:xxx/11
Configuration
class SimpleCaptchaConfig(BaseConfig):
""" 简单验证码配置 """
simple_captcha_cache_key = "SimpleCaptcha" # simple captcha redis cache key
simple_captcha_cache_key_expire = 6000 # simple captcha redis cache key expired time
class BlockPuzzleCaptchaConfig(BaseConfig):
""" 滑块验证码配置 """
block_puzzle_captcha_cache_key = "BlockPuzzleCaptcha" # block puzzle captcha redis cache key
block_puzzle_captcha_cache_key_expire = 6000 # block puzzle captcha redis cache key expired time
block_puzzle_captcha_check_offsetX = 10 # block puzzle captcha verify offset x
background_image_root_path = "resource/defaultImages/jigsaw/original" # block puzzle background images
template_image_root_path = "resource/defaultImages/jigsaw/slidingBlock" # block puzzle template images
pic_click_root_path = "resource/defaultImages/pic-click" # block puzzle pic check images
font_ttf_root_path = "resource/fonts/WenQuanZhengHei.ttf" # block puzzle font.ttf
font_water_text = "lei.wang" # block puzzle captcha water text
font_water_text_font_size = 22 # block puzzle captcha water text font size
class ClickWordCaptchaConfig(BaseConfig):
""" 文字点击验证码配置 """
click_word_captcha_cache_key = "ClickWordCaptcha" # click word captcha redis cache key
click_word_captcha_cache_key_expire = 6000 # click_word_captcha_cache_key expired time
font_ttf_root_path = "resource/fonts/WenQuanZhengHei.ttf" # click word captcha font.ttf
click_word_captcha_font_number = 4
click_word_captcha_font_size = 25
background_image_root_path = "resource/defaultImages/jigsaw/original" # click word captcha background images
click_word_captcha_text = "的一了是我不在人们有来他这上着个地到大里说就去子得也和那要下看天时过出小么起你都把好还多没为又可家学只以主会样年想生同老中十从自面前头道它后然走很像见两用她国动进成回什边作对开而己些现山民候经发工向事命给长水几义三声于高手知理眼志点心战二问但身方实吃做叫当住听革打呢真全才四已所敌之最光产情路分总条白话东席次亲如被花口放儿常气五第使写军吧文运再果怎定许快明行因别飞外树物活部门无往船望新带队先力完却站代员机更九您每风级跟笑啊孩万少直意夜比阶连车重便斗马哪化太指变社似士者干石满日决百原拿群究各六本思解立河村八难早论吗根共让相研今其书坐接应关信觉步反处记将千找争领或师结块跑谁草越字加脚紧爱等习阵怕月青半火法题建赶位唱海七女任件感准张团屋离色脸片科倒睛利世刚且由送切星导晚表够整认响雪流未场该并底深刻平伟忙提确近亮轻讲农古黑告界拉名呀土清阳照办史改历转画造嘴此治北必服雨穿内识验传业菜爬睡兴形量咱观苦体众通冲合破友度术饭公旁房极南枪读沙岁线野坚空收算至政城劳落钱特围弟胜教热展包歌类渐强数乡呼性音答哥际旧神座章帮啦受系令跳非何牛取入岸敢掉忽种装顶急林停息句区衣般报叶压慢叔背细"
当你需要针对定制化配置操作时,你需要重写对应的属性信息,并传入对应的验证码中:demo
from common_captcha.config import BlockPuzzleCaptchaConfig as _baseConfig
class BlockPuzzleCaptchaConfig(_baseConfig):
font_water_text_font_size = 30
font_water_text = "中国传媒大学"
简单验证码:
from common_captcha.strategy.simple_captcha import SimpleCaptcha
simple_captcha = SimpleCaptcha(redis_url="redis://xxxxxx:xxxxxx@xxxxx:xxx/11", configs=BlockPuzzleCaptchaConfig)
print(simple_captcha.get())
print(simple_captcha.verify({"token": "", "code": ""}))
滑块验证码:
from common_captcha.strategy.block_puzzle_captcha import BlockPuzzleCaptcha
block_captcha = BlockPuzzleCaptcha(redis_url="redis://xxxxxx:xxxxxx@xxxxx:xxx/11")
print(block_captcha.get())
print(block_captcha.verify(token="", point_json={"x": "", "y": ""}))
点击文字验证码:
from common_captcha.strategy.click_word_captcha import ClickWordCaptcha
click_captcha = ClickWordCaptcha(redis_url="redis://xxxxxx:xxxxxx@xxxxx:xxx/11")
token = "2a6d0134672845469904d9d541c93f60"
point_jsons = [
{
"x": 17,
"y": 187
},
{
"x": 140,
"y": 43
},
{
"x": 193,
"y": 64
}
]
print(click_captcha.verify(token, point_jsons))
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file common_captcha-1.0.5.tar.gz.
File metadata
- Download URL: common_captcha-1.0.5.tar.gz
- Upload date:
- Size: 8.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b871402b6e05e51cb79e80e7cffc4f60c69410c3c68d20f03526ec70dde56467
|
|
| MD5 |
01c770cd891afb421bfb24bf12de4897
|
|
| BLAKE2b-256 |
266c924f3d0941f91174d5348ca712ad142eaf0a877d175e9a7c135b70ac9c59
|
File details
Details for the file common_captcha-1.0.5-py2.py3-none-any.whl.
File metadata
- Download URL: common_captcha-1.0.5-py2.py3-none-any.whl
- Upload date:
- Size: 8.4 MB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b367796f2a91b5bbb58c2fcd5413f377b4ff11c000c4dc0fda74232b1bd38560
|
|
| MD5 |
9e98e79eccd4b52cdd80325451126d0a
|
|
| BLAKE2b-256 |
81680bdd18ca914864763204d8643e32ff9b9f75897f0779bdfd4a3c4980a2ad
|