Challenge - 5 Problems
Remember Me Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What happens when 'remember me' is enabled in Flask-Login?
In a Flask app using Flask-Login, if a user logs in with the 'remember me' option checked, what is the expected behavior on the next visit after closing the browser?
Attempts:
2 left
💡 Hint
Think about how cookies work with 'remember me' in web apps.
✗ Incorrect
When 'remember me' is enabled, Flask-Login sets a persistent cookie that keeps the user logged in even after the browser is closed and reopened.
📝 Syntax
intermediate2:00remaining
Correct way to implement 'remember me' in Flask-Login login_user call
Which of the following is the correct way to call login_user() with 'remember me' enabled in Flask-Login?
Flask
from flask_login import login_user # user is a valid user object # Which call is correct?
Attempts:
2 left
💡 Hint
Check the expected type of the 'remember' parameter in login_user.
✗ Incorrect
The 'remember' parameter expects a boolean value. Only True or False are valid.
🔧 Debug
advanced2:00remaining
Why does 'remember me' not persist after browser restart?
A developer uses Flask-Login with 'remember me' enabled, but after closing and reopening the browser, the user is logged out. What is the most likely cause?
Flask
login_user(user, remember=True) # Flask app config: app.config['REMEMBER_COOKIE_DURATION'] = timedelta(days=7) # User complains they must log in again after closing browser.
Attempts:
2 left
💡 Hint
Think about what controls cookie persistence in browsers.
✗ Incorrect
If the browser clears cookies on exit, the persistent 'remember me' cookie is deleted, so the user is logged out.
🧠 Conceptual
advanced2:00remaining
Security risk of 'remember me' feature in Flask apps
What is a common security risk when implementing 'remember me' functionality in Flask applications?
Attempts:
2 left
💡 Hint
Consider what happens if someone else gets the cookie stored on your device.
✗ Incorrect
The persistent cookie can be stolen and used by attackers to impersonate the user, so secure cookie handling is important.
❓ state_output
expert2:00remaining
What is the value of current_user.is_authenticated after browser restart with 'remember me'?
Given this Flask-Login setup with 'remember me' enabled, what will be the value of current_user.is_authenticated after the user closes and reopens the browser?
Flask
from flask_login import LoginManager, current_user, login_user from flask import Flask from datetime import timedelta app = Flask(__name__) app.secret_key = 'secret' login_manager = LoginManager(app) class User: def __init__(self, id): self.id = id @property def is_authenticated(self): return True @login_manager.user_loader def load_user(user_id): return User(user_id) # User logs in with remember=True user = User('123') login_user(user, remember=True) # Browser is closed and reopened # What is current_user.is_authenticated?
Attempts:
2 left
💡 Hint
Check how is_authenticated is defined in the User class.
✗ Incorrect
The User class defines is_authenticated as a property, which Flask-Login expects. Accessing current_user.is_authenticated returns True.