From 62804d242c295de7c5c4e76a7b54095e46c75785 Mon Sep 17 00:00:00 2001 From: qing <1776177662@qq.com> Date: Tue, 28 Jul 2026 10:24:48 +0800 Subject: [PATCH] =?UTF-8?q?ui:=20=E9=AA=8C=E8=AF=81=E7=A0=81=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=204=20=E4=BD=8D=EF=BC=8C=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E5=9B=BE=E7=89=87=E7=A7=BB=E5=88=B0=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E5=B7=A6=E4=BE=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit captcha 服务 CAPTCHA_LEN 调整为 4 并适配字符间距;登录页验证码图片与输入框换序,同一行展示更紧凑。 --- captcha/README.md | 2 +- captcha/captcha_service.py | 4 ++-- static/public/login.html | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/captcha/README.md b/captcha/README.md index 43376d7..0b388f4 100644 --- a/captcha/README.md +++ b/captcha/README.md @@ -6,7 +6,7 @@ ## 功能特性 -- **图片验证码生成**:5 位字符(字母 + 数字),自动排除易混淆字符(`l I 1 O 0 o`) +- **图片验证码生成**:4 位字符(字母 + 数字),自动排除易混淆字符(`l I 1 O 0 o`) - **Token 机制**:每次生成图片返回唯一 Token(32 位十六进制),校验时**一次性消费**,防止重放 - **过期自动清理**:Token 默认 300 秒(5 分钟)失效;`image` 路由请求时顺带清理过期项 - **线程安全**:使用锁(`STORE_LOCK`)保护内存存储,支持并发请求 diff --git a/captcha/captcha_service.py b/captcha/captcha_service.py index 009cb8a..054749b 100644 --- a/captcha/captcha_service.py +++ b/captcha/captcha_service.py @@ -38,7 +38,7 @@ from pymsg import MsgServer # noqa: E402 # ── 配置 ──────────────────────────────────────────────────────────────── -CAPTCHA_LEN = 5 +CAPTCHA_LEN = 4 CAPTCHA_TTL = 300 # Token 有效期(秒) CHARS = string.ascii_letters + string.digits @@ -63,7 +63,7 @@ def generate_image(text): for i, ch in enumerate(text): color = random.choice([(30, 30, 30), (50, 80, 150), (150, 50, 50), (50, 130, 50)]) y = random.randint(2, 12) - x = 10 + i * 28 + random.randint(-3, 3) + x = 15 + i * 32 + random.randint(-3, 3) # 4 位字符在 160px 宽度内均匀分布 try: font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf", random.choice([28, 30, 32, 34])) diff --git a/static/public/login.html b/static/public/login.html index e0438a4..41af9e4 100644 --- a/static/public/login.html +++ b/static/public/login.html @@ -18,8 +18,8 @@ - - 加载中… + 加载中… +