Django Authentication & Security Flashcards
6 cards from real Django practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 6 Django Authentication & Security flashcards as text
What is Django's `AbstractUser` model used for?
Answer: Extending the built-in User model with additional fields while keeping all default auth features
AbstractUser allows you to add custom fields to Django's built-in user model by subclassing it, which is the recommended approach for custom user models.
What does `logout(request)` do in Django?
Answer: Clears the authenticated user from the session and flushes session data
logout() removes the user's session data, ensuring they are fully logged out and protecting against session fixation attacks.
What is the purpose of Django's `SecurityMiddleware`?
Answer: Sets security headers like HSTS, X-Content-Type-Options, and enforces HTTPS
SecurityMiddleware handles several security-related HTTP headers and redirects HTTP to HTTPS based on settings like SECURE_HSTS_SECONDS and SECURE_SSL_REDIRECT.
Which setting must be set to use a custom user model in Django?
Answer: AUTH_USER_MODEL
AUTH_USER_MODEL = 'myapp.CustomUser' must be set before the first migration to tell Django which model to use for authentication.
What does Django's `check_password(raw_password, encoded)` function do?
Answer: Verifies a plaintext password against a stored hashed password
check_password() hashes the raw password using the same algorithm identified in the encoded hash and compares them securely using a constant-time comparison.
What is Django's `UserCreationForm` used for?
Answer: A built-in form for creating a new user with password confirmation
UserCreationForm provides username and two password fields with matching validation, and saves the user with a properly hashed password.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy