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
Which function authenticates a user with a username and password in Django?
Answer: authenticate(request, username=username, password=password)
authenticate() checks credentials against all configured authentication backends and returns a User object on success or None on failure.
What does `login(request, user)` do in Django?
Answer: Attaches the user to the session and marks them as logged in
login() saves the user's ID to the session using Django's session framework, establishing the logged-in state across requests.
What does Django's CSRF middleware protect against?
Answer: Cross-Site Request Forgery attacks where malicious sites submit requests on behalf of authenticated users
CSRF middleware validates a secret token in POST/PUT/DELETE requests to ensure they originate from the same site, not a malicious third-party page.
Which Django setting controls password hashing algorithms?
Answer: PASSWORD_HASHERS
PASSWORD_HASHERS is a list of hasher classes in priority order; Django uses the first one for new passwords and can upgrade older hashes automatically.
What does `request.user.is_authenticated` return for an anonymous user?
Answer: False
For anonymous users, Django provides an AnonymousUser object whose is_authenticated property always returns False.
Which decorator enforces that a view can only be accessed by users with a specific permission?
Answer: @permission_required('app.permission_codename')
permission_required() checks if the logged-in user has the specified permission and redirects to login if not, similar to @login_required.
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