0
0
Flaskframework~10 mins

Remember me functionality in Flask - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set a cookie named 'remember_token' with the user's token.

Flask
response.set_cookie('remember_token', [1])
Drag options to blanks, or click blank then click option'
Auser_token
Bsession_id
Ccsrf_token
Drequest_token
Attempts:
3 left
💡 Hint
Common Mistakes
Using session_id or csrf_token instead of the user's token.
2fill in blank
medium

Complete the code to check if the 'remember_token' cookie exists in the request.

Flask
if [1] in request.cookies:
Drag options to blanks, or click blank then click option'
A'remember_token'
Bsession
Cuser_token
D'csrf_token'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for 'session' or 'csrf_token' instead of 'remember_token'.
3fill in blank
hard

Fix the error in this code that tries to set a cookie with expiration for 'remember me' functionality.

Flask
response.set_cookie('remember_token', token, max_age=[1])
Drag options to blanks, or click blank then click option'
A3600
B60*60*24*30
CNone
D60
Attempts:
3 left
💡 Hint
Common Mistakes
Using 3600 (1 hour) or 60 (1 minute) which is too short.
4fill in blank
hard

Fill both blanks to retrieve the token from the cookie and verify the user.

Flask
token = request.cookies.get([1])
user = User.query.filter_by([2]=token).first()
Drag options to blanks, or click blank then click option'
A'remember_token'
B'session_id'
Cremember_token
Dtoken
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'session_id' or 'remember_token' variable incorrectly.
5fill in blank
hard

Fill all three blanks to set a secure, HTTP-only cookie with a 7-day expiration.

Flask
response.set_cookie([1], [2], max_age=[3], secure=True, httponly=True)
Drag options to blanks, or click blank then click option'
A'remember_token'
Buser_token
C60*60*24*7
D'session_token'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong cookie names or wrong max_age values.