🌐
Readthedocs
flask-login.readthedocs.io
Flask-Login 0.7.0 documentation
In these cases, you should use the request_loader callback. This callback should behave the same as your user_loader callback, except that it accepts the Flask request instead of a user_id. For example, to support login from both a url argument and from Basic Auth using the Authorization header:
🌐
Reddit
reddit.com β€Ί r/flask β€Ί flask-login vs. flask-user vs flask-security
r/flask on Reddit: Flask-Login vs. Flask-User vs Flask-Security
May 27, 2019 -

Can someone clarify what's going on between these three extensions?

As I understand it, Flask-Security builds upon Flask-Login by integrating other extensions like passlib, itdangerous, flask-wtf, flask-principal, etc. So Flask-Security trumps Flask-Login in this instance.

Then we have Flask-User, looking at it's github, it also has Flask-Login as a dependency. So this also builds upon Flask-Login.

However, Flask-User had it's last commit 20 days ago, and Flask-Security had it's last commit in October of 2018 and the build is failing. No data for Flask-User status.

The consensus seems to veer towards flask-security. But I'm veering towards Flask-User with the little understanding of the real world differences. I'll be creating all my database records with uuid's as the ID's. What would you guys choose and what are the pros and cons of them? Are there any real alternatives?

Discussions

python - Flask user-roles, authorization, login and security, or principal? - Stack Overflow
This question has a similar question that was posted 7 years ago. I want to know what is pertinent currently. Flask-auth, Principal and Flask Security I have found so much documentation on login an... More on stackoverflow.com
🌐 stackoverflow.com
python - Flask-Login vs Flask-Security for Production Environment - Stack Overflow
I am building out a feature for users to register, login, authenticate and authorize themselves, specifically using Python (Flask) for the backend. I've found a few solutions such as flask-login and More on stackoverflow.com
🌐 stackoverflow.com
python - Flask user authentication - Stack Overflow
I have an application that will use flask and mongodb; I will probably host it on rackspace. I need to understand how flask authenticating works. I have not found much information on the subject. Is More on stackoverflow.com
🌐 stackoverflow.com
python - flask-login: can't understand how it works - Stack Overflow
I'm trying to understand how Flask-Login works. I see in their documentation that they use a pre-populated list of users. I want to play with a database-stored users list. However, I don't unders... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Miguel Grinberg
blog.miguelgrinberg.com β€Ί post β€Ί the-flask-mega-tutorial-part-v-user-logins
The Flask Mega-Tutorial, Part V: User Logins - miguelgrinberg.com
December 3, 2023 - This extension manages the user logged-in state, so that for example users can log in to the application and then navigate to different pages while the application "remembers" that the user is logged in. It also provides the "remember me" functionality that allows users to remain logged in even after closing the browser window. To be ready for this chapter, you can start by installing Flask-Login in your virtual environment:
🌐
AskPython
askpython.com β€Ί home β€Ί flask user authentication – how to setup user login in flask?
Flask User Authentication - How to Setup User Login in Flask? - AskPython
July 7, 2022 - Flask-login uses Cookie-based Authentication. When the client logins via his credentials, Flask creates a session containing the user ID and then sends the session ID to the user via a cookie, using which he can log in and out as and when required.
🌐
Readthedocs
flask-user.readthedocs.io
Flask-User v1.0 β€” Flask-User v1.0 documentation
So, you’re writing a Flask web application and would like to authenticate your users. You start with a simple Login page, but soon enough you’ll need to handle:
🌐
Hackers and Slackers
hackersandslackers.com β€Ί flask-login-user-authentication
Handle User Accounts & Authentication in Flask with Flask-Login
April 28, 2024 - Flask-Login is a dope library that handles all aspects of user management, including user signups, encrypting passwords, managing sessions, and securing parts of our app behind login walls. Flask-Login also happens to play nicely with other Flask libraries we're already familiar with!
🌐
Python Basics
pythonbasics.org β€Ί flask-login
Flask Login Tutorial - Python Tutorial
You can use the Flask-Login module to do access control. It provides user session management for Flask: logging in, logging out, and remembering session.
Find elsewhere
🌐
InterSystems
community.intersystems.com β€Ί post β€Ί flask-and-flask-login-guide-building-secure-web-applications
Flask and Flask-Login: A Guide to Building Secure Web Applications | IDC
January 9, 2024 - Flask-Login simplifies the process of adding user authentication to a Flask application, making it easy to protect your application's resources from unauthorized access. It provides user session management for Flask.
🌐
Real Python
realpython.com β€Ί using-flask-login-for-user-management-with-flask
Using Flask-Login for User Management with Flask
It's a great starting point for any scalable Flask web app that you wish to develop in the future, from basic web pages to complex web applications. ... After you implement the main functionality of a web project, it's good to understand how your users interact with your app and where they may run into errors.
Top answer
1 of 7
88

Flask-login doesn't actually have a user backend, it just handles the session machinery to help you login and logout users. You have to tell it (by decorating methods), what represents a user and it is also up to you to figure out how to know if a user is "active" or not (since being "active" can mean different things in different applications).

You should read the documentation and be sure what it does and does not do. Here I am only going to concentrate on wiring it up with the db backend.

To start off with, define a user object; which represents properties for your users. This object can then query databases, or LDAP, or whatever and it is the hook that connects the login mechanism with your database backend.

I will be using the login example script for this purpose.

class User(UserMixin):
    def __init__(self, name, id, active=True):
        self.name = name
        self.id = id
        self.active = active

    def is_active(self):
        # Here you should write whatever the code is
        # that checks the database if your user is active
        return self.active

    def is_anonymous(self):
        return False

    def is_authenticated(self):
        return True

Once you have the user object created, you need to write a method that loads the user (basically, creates an instance of the User class from above). This method is called with the user id.

@login_manager.user_loader
def load_user(id):
     # 1. Fetch against the database a user by `id` 
     # 2. Create a new object of `User` class and return it.
     u = DBUsers.query.get(id)
    return User(u.name,u.id,u.active)

Once you have these steps, your login method does this:

  1. Checks to see if the username and password match (against your database) - you need to write this code yourself.

  2. If authentication was successful you should pass an instance of the user to login_user()

2 of 7
19

Flask-login will try and load a user BEFORE every request. So yes, your example code below will be called before every request. It is used to check what userid is in the current session and will load the user object for that id.

@login_manager.user_loader
def load_user(userid):
    #print 'this is executed',userid
    return user(userid, 'asdf')        

If you look at the Flask-login source code on github, there is a line under function init_app which goes:

app.before_request(self._load_user)

So before every request, the _load_user function is called. The _load_user functions actually calls another function "reload_user()" based on conditions. And finally, reload_user() function calls your callback function that you wrote (load_user() in your example).

Also, flask-login only provides the mechanism to login/logout a user. It does not care if you are using mysql database.

🌐
freeCodeCamp
freecodecamp.org β€Ί news β€Ί how-to-authenticate-users-in-flask
How to Authenticate Users in Flask with Flask-Login
November 1, 2021 - In this article, we'll walk through the steps to create a user authentication web app with Flask, a micro web framework. For authentication, we'll use the Python library flask_login.
🌐
GitHub
github.com β€Ί maxcountryman β€Ί flask-login
GitHub - maxcountryman/flask-login: Flask user session management. Β· GitHub
It handles the common tasks of logging in, logging out, and remembering your users' sessions over extended periods of time. Flask-Login is not bound to any particular database system or permissions model.
Starred by 3.7K users
Forked by 817 users
Languages Β  Python
🌐
Reddit
reddit.com β€Ί r/flask β€Ί flask-login vs flask-user
r/flask on Reddit: Flask-Login vs Flask-User
March 7, 2020 -

Does Flask-Login and Flask-User work hand-in-hand? Or is one an alternative to the other?

From reading the docs, it looks like Flask Login handles authentication while Flask user handles a list of other things: registration, email confirmation, changing usernames and passwords, and forgotten passwords.

is there any overlap in their responsibilities? Or do they work together to create 'the complete authentication and user' system?

🌐
DigitalOcean
digitalocean.com β€Ί community β€Ί tutorials β€Ί how-to-add-authentication-to-your-app-with-flask-login
Add Authentication to Flask Apps with Flask-Login | DigitalOcean
October 22, 2025 - Simplified Session Management: Flask-Login eliminates the hassle of handling session cookies and user tracking manually. It manages authentication state for you, providing a seamless experience whether users are logging in, logging out, or returning after a break.
🌐
Medium
medium.com β€Ί hacking-and-slacking β€Ί handle-user-accounts-authentication-in-flask-with-flask-login-944cc065b7f2
Handle User Accounts & Authentication in Flask with Flask-Login | by Todd Birchard | Hackers and Slackers | Medium
June 16, 2020 - Flask-Login is a dope library that handles all aspects of user management, including user signups, encrypting passwords, managing sessions, and securing parts of our app behind login walls. Flask-Login also happens to play nicely with other Flask libraries we’re already familiar with!
🌐
Pythonrepo
pythonrepo.com β€Ί repo β€Ί maxcountryman-flask-login-python-implementing-authentications-schemes
Flask user session management. | PythonRepo
December 21, 2021 - It handles the common tasks of logging in, logging out, and remembering your users' sessions over extended periods of time. Flask-Login is not bound to any particular database system or permissions model.