Python data access and security · Concept
Storing passwords and secrets
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe 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
- Which algorithm does Django use by default, and what would you change?
- How do you move existing users to a new algorithm without forcing a reset?
SECRET_KEYleaked in a public repository. What do you do?- What does
DEBUG = Trueexpose in production? - 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], withArgon2PasswordHasherfirst inPASSWORD_HASHERS). FastAPI's docs usepwdlibwith 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-environorpydantic-settings(SecretStrhides values in logs and reprs)..envfiles only on laptops, and in.gitignore. - Leaked
SECRET_KEY: rotate it, keep the old one inSECRET_KEY_FALLBACKSfor 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 = Trueshows detailed error pages with settings (Django hides only names that look secret, such as those containingKEY,TOKENorPASS), source code and request data, and keeps recent SQL queries in memory.python manage.py check --deploylists 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 voicePractise 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.