Skip to content

Remember Me Functionality

By default, login state ends when the browser closes (session cookie).

“Remember me” uses a longer-lived cookie so users stay logged in.

diagram why remember me is a second, longer-lived credential mermaid
The session cookie dies when the browser closes. Remember-me is a separate cookie with its own long lifetime, and Flask-Login uses it to rebuild the session when the session cookie is gone. That is convenient and it is also a bigger window for a stolen cookie, which is why sensitive actions should re-ask for the password.
python
from flask_login import login_user
 
login_user(user, remember=True)

Often the user chooses this via a checkbox.

Remember-me is convenient but can be risky:

  • if someone gains access to the device, they stay logged in

Mitigations:

  • allow users to revoke sessions
  • set reasonable expiration times
  • require re-auth for sensitive actions

Flask-Login allows setting:

  • REMEMBER_COOKIE_DURATION

You can set it in app config.

For banking/high-security apps:

  • avoid long remember sessions
  • require multi-factor authentication (MFA)

For normal apps:

  • remember-me is common and acceptable.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading