password_strength_router.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. """
  2. 密码强度检测API路由
  3. 提供密码强度实时检测的API端点
  4. """
  5. from fastapi import APIRouter
  6. from app.schemas.password_strength_schema import (
  7. PasswordStrengthRequest,
  8. PasswordStrengthResponse
  9. )
  10. from app.services.password_strength_service import PasswordStrengthService
  11. router = APIRouter(prefix="/api/password", tags=["密码强度"])
  12. @router.post(
  13. "/check-strength",
  14. response_model=PasswordStrengthResponse,
  15. summary="检测密码强度",
  16. description="实时检测密码强度,返回强度等级、分数和改进建议"
  17. )
  18. def check_password_strength(request: PasswordStrengthRequest):
  19. """
  20. 检测密码强度
  21. 强度等级:
  22. - weak(弱): 只有小写字母和数字,或单一类型
  23. - medium(中): 包含小写字母、数字和特殊符号(至少2种)
  24. - strong(强): 包含大小写字母、数字和特殊符号(至少3种,且包含大小写)
  25. """
  26. return PasswordStrengthService.check_password_strength(request.password)