Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .coverage
Binary file not shown.
7 changes: 4 additions & 3 deletions app/services/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# Signup responds identically whether or not the email is already registered,
# so an attacker can't enumerate accounts through the signup endpoint.
GENERIC_SIGNUP_MESSAGE = "Please check your email to activate your account."
VERIFICATION_CODE_LENGTH = settings.VERIFICATION_CODE_LENGTH


# --- Redis key builders (single source of truth for key formats) ------------
Expand Down Expand Up @@ -150,7 +151,7 @@ async def initiate_password_reset(
if not user or await email_cooldown_active("reset", email):
return {"detail": "Password Reset Code Sent"}

code = generate_random_code(6)
code = generate_random_code(VERIFICATION_CODE_LENGTH)
await redis_manager.cache_json_item(
reset_code_key(email), {"code": code}, ttl=60 * 30
)
Expand Down Expand Up @@ -287,7 +288,7 @@ async def signup_user(

user = await create_user(data, session)

code = generate_random_code(6)
code = generate_random_code(VERIFICATION_CODE_LENGTH)
await redis_manager.cache_json_item(
activation_code_key(data.email), {"code": code}, ttl=60 * 30
)
Expand All @@ -310,7 +311,7 @@ async def resend_activation_code(
if not user or await email_cooldown_active("activation", email):
return {"detail": "Activation Code Sent"}

code = generate_random_code(6)
code = generate_random_code(VERIFICATION_CODE_LENGTH)
await redis_manager.cache_json_item(
activation_code_key(email), {"code": code}, ttl=60 * 30
)
Expand Down
3 changes: 3 additions & 0 deletions app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class Settings(BaseSettings):
JWT_SECRET: str = "" # REQUIRED in production (DEBUG=False); see validator below
JWT_ALGORITHM: str = "HS256" # optional environement variable with default value

# ensures the length of the otp codes used across the app is consistent
VERIFICATION_CODE_LENGTH: int = 6

REDIS_HOST: str = "localhost"
REDIS_PORT: int = 6379

Expand Down
Loading