Skip to the page

Python data access and security · Concept

Storing passwords and secrets

The interviewer asks

How should a Django or FastAPI app store user passwords? And where should secrets like SECRET_KEY, database passwords and API keys live?

Then

Follow-ups the interviewer asks next

  1. Which algorithm does Django use by default, and what would you change?
  2. How do you move existing users to a new algorithm without forcing a reset?
  3. SECRET_KEY leaked in a public repository. What do you do?
  4. What does DEBUG = True expose in production?
  5. How do you check a Django project's security settings quickly?

The answer

What a strong answer covers

  • Never store passwords, only slow, salted hashes. Django's default is PBKDF2-SHA256 with an iteration count raised every release; Django's docs recommend Argon2 (pip install django[argon2], with Argon2PasswordHasher first in PASSWORD_HASHERS). FastAPI's docs use pwdlib with Argon2.
  • Upgrade on login: Django re-hashes with the preferred hasher when someone logs in; keep the old hashers in the list so old hashes still verify.
  • Secrets live in environment variables or a secret manager (AWS Secrets Manager, Vault, Kubernetes secrets fed from one), read at startup with django-environ or pydantic-settings (SecretStr hides values in logs and reprs). .env files only on laptops, and in .gitignore.
  • Leaked SECRET_KEY: rotate it, keep the old one in SECRET_KEY_FALLBACKS for a short time so sessions don't all break, rotate the other secrets in the same repo, and treat them as exposed even after cleaning git history.
  • DEBUG = True shows detailed error pages with settings (Django hides only names that look secret, such as those containing KEY, TOKEN or PASS), source code and request data, and keeps recent SQL queries in memory.
  • python manage.py check --deploy lists missing security settings (DEBUG, secure cookies, SECURE_HSTS_SECONDS).

The red pen

Common traps

Avoid:MD5 or plain SHA-256; encrypting passwords (reversible); secrets in settings.py "because the repo is private".

Practise this out loud

Say your answer out loud to an AI interviewer that follows up, and get a score for it.

Practise by voice

Practise questions like this out loud

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview