ui: 验证码改为 4 位,登录页图片移到输入框左侧

captcha 服务 CAPTCHA_LEN 调整为 4 并适配字符间距;登录页验证码图片与输入框换序,同一行展示更紧凑。
This commit is contained in:
qing committed 2026-07-28 10:24:48 +08:00
1 parent a5e581ef24
commit 62804d242c
3 files changed
+5 -5

No files matched your search

+1 -1
View File
@@ -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`)保护内存存储,支持并发请求
+2 -2
View File
@@ -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]))
+2 -2
View File
@@ -18,8 +18,8 @@
<input type="password" id="loginPassword" placeholder="请输入密码">
<span id="pwdTip"></span>
<label>验证码:</label>
<input type="text" id="captchaAnswer" placeholder="请输入验证码" maxlength="5" autocomplete="off" style="width:110px">
<img id="captchaImg" alt="加载中…" title="点击刷新验证码" style="width:120px;height:38px;vertical-align:middle;cursor:pointer;margin-left:8px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box">
<img id="captchaImg" alt="加载中…" title="点击刷新验证码" style="width:120px;height:38px;vertical-align:middle;cursor:pointer;margin-right:8px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box">
<input type="text" id="captchaAnswer" placeholder="请输入验证码" maxlength="4" autocomplete="off" style="width:110px">
<span id="captchaTip"></span>
</div>
<div class="form-actions">