Files
mkdocs/docs/dify/密码输入错误次数超过限制时的机制.md

70 lines
1.7 KiB
Markdown
Raw Permalink Normal View History

2026-01-14 17:55:16 +08:00
## 错误原因
这是 Dify 的登录安全机制:当同一邮箱的密码错误次数超过限制时,会临时锁定该邮箱的登录。
### 具体机制
1. 错误次数限制:最多允许 5 次错误登录尝试LOGIN_MAX_ERROR_LIMITS = 5
2. 锁定时间:默认 24 小时86400 秒)
3. 计数方式:每次密码错误会增加计数,存储在 Redis 中
### 相关代码
login.pyLines 95-97
is_login_error_rate_limit = AccountService.is_login_error_rate_limit(args.email)
if is_login_error_rate_limit:
    raise EmailPasswordLoginLimitError()
account_service.pyLines 786-792
def add_login_error_rate_limit(email: str):
    key = f"login_error_rate_limit:{email}"
    count = redis_client.get(key)
    if count is None:
        count = 0
    count = int(count) + 1
    redis_client.setex(key, dify_config.LOGIN_LOCKOUT_DURATION, count)
account_service.pyLines 796-805
def is_login_error_rate_limit(email: str) -> bool:
    key = f"login_error_rate_limit:{email}"
    count = redis_client.get(key)
    if count is None:
        return False
    count = int(count)
    if count > AccountService.LOGIN_MAX_ERROR_LIMITS:
        return True
    return False
### 解决方案
1. 等待锁定时间结束(默认 24 小时)
2. 管理员可在 Redis 中删除该邮箱的计数记录:
   redis-cli DEL "login_error_rate_limit:your-email@example.com"
3. 使用邮箱验证码登录(如果已启用),不受此限制影响
这是防止暴力破解的安全措施,建议等待锁定时间结束或联系管理员处理。