Bird
Raised Fist0
Flaskframework~20 mins

Remember me functionality in Flask - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Remember Me Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate
2: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?
AThe user stays logged in even after closing and reopening the browser.
BThe user is logged out immediately after closing the browser.
CThe user session expires after 5 minutes regardless of activity.
DThe user must log in again every time they refresh the page.
Attempts:
2 left
💡 Hint
Think about how cookies work with 'remember me' in web apps.
📝 Syntax
intermediate
2: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?
Alogin_user(user, remember='true')
Blogin_user(user, remember='yes')
Clogin_user(user, remember=1)
Dlogin_user(user, remember=True)
Attempts:
2 left
💡 Hint
Check the expected type of the 'remember' parameter in login_user.
🔧 Debug
advanced
2: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.
AThe browser is set to clear cookies on exit, removing the remember cookie.
BThe REMEMBER_COOKIE_DURATION is too short and expires immediately.
CThe user object does not have an 'is_authenticated' property.
DFlask-Login does not support 'remember me' functionality.
Attempts:
2 left
💡 Hint
Think about what controls cookie persistence in browsers.
🧠 Conceptual
advanced
2:00remaining
Security risk of 'remember me' feature in Flask apps
What is a common security risk when implementing 'remember me' functionality in Flask applications?
AThe 'remember me' feature disables HTTPS encryption.
BIt causes the server to store user passwords in plain text.
CIf the remember cookie is stolen, an attacker can access the user's account without logging in.
DIt automatically grants admin privileges to remembered users.
Attempts:
2 left
💡 Hint
Consider what happens if someone else gets the cookie stored on your device.
❓ state_output
expert
2: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?
ANone
BTrue
CFalse
DRaises AttributeError
Attempts:
2 left
💡 Hint
Check how is_authenticated is defined in the User class.

Practice

(1/5)
1. What does the remember=True parameter do when used with login_user() in Flask-Login?
easy
A. Logs the user out immediately after login.
B. Deletes the user's account after login.
C. Prevents the user from logging in.
D. Keeps the user logged in across browser sessions using cookies.

Solution

  1. Step 1: Understand the purpose of remember=True

    This parameter tells Flask-Login to store a cookie that keeps the user logged in even after closing the browser.
  2. Step 2: Compare with other options

    Options A, C, and D describe actions that do not relate to keeping the user logged in across sessions.
  3. Final Answer:

    Keeps the user logged in across browser sessions using cookies. -> Option D
  4. Quick Check:

    Remember me = persistent login [OK]
Hint: Remember me means stay logged in after closing browser [OK]
Common Mistakes:
  • Thinking remember=True logs out user
  • Confusing remember with user registration
  • Assuming remember deletes user data
2. Which of the following is the correct way to enable 'remember me' when logging in a user in Flask?
easy
A. login_user(user, remember=1)
B. login_user(user, remember='yes')
C. login_user(user, remember=True)
D. login_user(user, remember='false')

Solution

  1. Step 1: Check the correct parameter type

    The remember parameter expects a boolean value, so True is correct.
  2. Step 2: Analyze other options

    Options A, B, and D use integer or string instead of boolean, which is incorrect. login_user(user, remember='false') uses string 'false' which is not boolean False.
  3. Final Answer:

    login_user(user, remember=True) -> Option C
  4. Quick Check:

    Boolean True enables remember me [OK]
Hint: Use boolean True for remember parameter [OK]
Common Mistakes:
  • Passing strings instead of boolean
  • Using numbers instead of boolean
  • Using 'false' string instead of False
3. Given this Flask code snippet:
from flask_login import login_user

user = get_user()
login_user(user, remember=True)

What will happen if the user closes and reopens the browser?
medium
A. The user will remain logged in automatically.
B. The user will be logged out immediately.
C. The user will see an error message.
D. The user must log in again manually.

Solution

  1. Step 1: Understand the effect of remember=True

    This stores a cookie that keeps the user logged in even after browser restart.
  2. Step 2: Predict user state after reopening browser

    Because of the cookie, the user session persists, so the user stays logged in automatically.
  3. Final Answer:

    The user will remain logged in automatically. -> Option A
  4. Quick Check:

    Remember me keeps session after browser close [OK]
Hint: Remember me means no login needed after browser restart [OK]
Common Mistakes:
  • Assuming user is logged out after closing browser
  • Expecting error on reopening browser
  • Confusing remember with session timeout
4. What is wrong with this Flask code snippet for 'remember me' functionality?
login_user(user, remember='True')
medium
A. The user variable is not defined.
B. The remember parameter should be a boolean, not a string.
C. login_user does not accept a remember parameter.
D. The code is correct and will work as expected.

Solution

  1. Step 1: Check parameter type for remember

    The remember parameter must be a boolean value, not a string.
  2. Step 2: Validate other options

    User variable is assumed defined; login_user accepts remember; so only parameter type is wrong.
  3. Final Answer:

    The remember parameter should be a boolean, not a string. -> Option B
  4. Quick Check:

    remember must be True/False boolean [OK]
Hint: Use True without quotes for remember [OK]
Common Mistakes:
  • Passing 'True' as string instead of boolean
  • Forgetting to define user variable
  • Assuming remember is unsupported
5. You want to implement a logout button that clears the 'remember me' session in Flask. Which code snippet correctly logs out the user and clears the remembered login?
hard
A. from flask_login import logout_user logout_user()
B. from flask_login import logout_user logout_user(remember=False)
C. from flask_login import logout_user logout_user(user)
D. from flask_login import logout_user logout_user(clear=True)

Solution

  1. Step 1: Understand logout_user behavior

    Calling logout_user() clears the user session and any remember me cookies automatically.
  2. Step 2: Analyze other options

    logout_user does not take parameters like remember, user, or clear; these cause errors or are ignored.
  3. Final Answer:

    from flask_login import logout_user logout_user() -> Option A
  4. Quick Check:

    logout_user() clears session and remember me [OK]
Hint: Use logout_user() without parameters to clear remember me [OK]
Common Mistakes:
  • Passing parameters to logout_user()
  • Not calling logout_user to clear remember me
  • Assuming remember must be cleared separately
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard