Flask-Security is now deprecated, so I wouldn't recommend using it in production. There is a fork of it called Flask Security Too but it doesn't seem very widely followed.

To be honest even when it was maintained it wasn't my favourite as I think it tried to do too much.

Flask-Login on the other hand is a solid library. It is very "flasky" in the sense that it is low level and deals with the really annoying stuff (creating a session, persisting it with cookies, delivering a current_user, putting certain routes behind a login_required decorator) and then letting you design your own flow and pull in the libraries you want.

For instance if you want social login or OAuth token storage then Flask-Dance, which integrates nicely with Flask-Login and is actively maintained, smashes Flask-Social which integrates with Flask-Security.

There is also Flask-User, which gets good reviews but last commit was in 2019, which is a little scary.

Answer from Super on Stack Overflow
🌐
Reddit
reddit.com › r/flask › how safe is building my own login vs using flask-login extension?
r/flask on Reddit: How safe is building my own login VS using Flask-Login extension?
October 2, 2025 -

Someone said that Flask session can be easily hacked via console and, depending on the implementation, they can inject a user's detail to impersonate them. How real is this?

I don't like much Flask-Login, feels limiting and weird... but I might be the one weird for this lol.

🌐
Medium
medium.com › @mathur.danduprolu › user-authentication-and-authorization-in-flask-building-secure-login-and-access-control-part-5-7-59679a08cdc3
User Authentication and Authorization in Flask: Building Secure Login and Access Control [Part 5/7] | by Mathur Danduprolu | Medium
November 13, 2024 - You’ve just implemented user authentication and authorization in Flask using Flask-Login. This setup includes registration, login, session management, and restricted routes, creating a secure foundation for your web application.
🌐
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 - Flask-Login is the most popular authentication library for Flask applications, handling user sessions, login state, and route protection with minimal configuration. This tutorial shows you how to implement secure user authentication in Flask using Flask-Login, Flask-SQLAlchemy, and Werkzeug’s password hashing utilities.
🌐
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 and Flask-Login are robust tools that can help you build secure web applications in Python. Flask provides a simple but powerful API for making web applications, and Flask-Login simplifies the process of adding user authentication and ...
Top answer
1 of 1
3

No, this wouldn't be considered secure. Just implement proper authentication and authorization instead. If you really still want the view to be random, just generate it randomly, but using proper authentication and authorization is still required to be 'secure'

The flask-login extension implements a lot of the boilerplate for this for you, making it a lot simpler with a lot more functionality.

Some other notes:

  • You probably don't want to use hash which is (1) not consistent, meaning users passwords change every reload and (2) is not secure in terms of cryptography.
  • You probably should store salted and hashed passwords, for example, using bcrypt or otherwise use a strong hashing algorithm.

Here, I'll provide an example using the standard lib hashlib.pbkdf2_hmac. You can also consider other strong password hashing algorithms like hashlib.scrypt. But be aware, we're still taking some shortcuts here.

For example, generate the salted and hashed password:

import hashlib
import secrets


username = salt = b'user1'
# generating and storing a random salt for each user would be more secure, too.
# salt = secrets.token_bytes(32)  # store this value somewhere

# generate a random password
# password = bytes(secrets.token_urlsafe(32), 'ascii')
password = b'pw1'  # static for this example
print(username, 'keep this safe:', str(password, 'ascii'))

salted_hashed = hashlib.pbkdf2_hmac('sha256', password, salt, iterations=500_000)
print('here is the hash', salted_hashed.hex())

This will produce an output like:

admin keep this safe: pw1
here is the hash aeca87e94befc6006398c776707e39cf79530500b273c3789661dbfcf2e86ffa

Then your app can store the salted & hashed password. Usually, this happens in a database, but for simplicity, we'll keep your dictionary approach.

Putting that all together, your app may look like this (without using flask-login):

import functools
import hashlib
from flask import session, Flask, request, flash, render_template, redirect, url_for
app = Flask(__name__)


USERS = {
    "user1": ['aeca87e94befc6006398c776707e39cf79530500b273c3789661dbfcf2e86ffa', "page_admin"],
    # ...
}

app.secret_key = b'super-secret'

def login_required(allowed_users='all'):
    def wrapper(view):
        @functools.wraps(view)
        def wrapped_view(*args, **kwargs):
            logged_in_user = session.get('user')
            if logged_in_user is None:
                print('authentication required')
                flash('authentication required')
                return redirect(url_for('page_login'))
            if allowed_users != 'all':
                if logged_in_user not in allowed_users:
                    return 'Not authorized', 403
                else:
                    return view(*args, **kwargs)
            else:  # if allowed_users not specified, any logged in user is OK
                return view(*args, **kwargs)
        return wrapped_view
    return wrapper


@app.route('/login', methods=['POST', 'GET'])
def page_login():
    if request.method == "POST":
        login = request.form["login"]
        if login in USERS:
            salt = bytes(login, 'ascii')
            pw = bytes(request.form['password'], 'ascii')
            password = hashlib.pbkdf2_hmac('sha256', pw, salt, iterations=500_000).hex()
            if password == USERS[login][0]:
                print('Successfully logged in')
                flash('successfully logged in')
                session['user'] = login
                landing_page = USERS[login][1]
                return redirect(url_for(landing_page))
            else:
                print('bad password')
                flash('bad login')
        else:
            print('unknown user')
            flash('bad login')
    return render_template("page_login.html")


@app.route('/lab/user')
@login_required()
def page_user():
    username = session.get('user')
    return f'Hello {username} (user)'

@app.route('/lab/admin')
@login_required(allowed_users=('user1',))
def page_admin():
    username = session.get('user')
    return f'Hello {username} (admin)'
🌐
Corgea
corgea.com › learn › flask-security-best-practices-2025
Flask Security Best Practices 2025 | Corgea
June 1, 2025 - For more detailed guidance, consult the OWASP Flask Security Cheat Sheet. Authentication controls who can log into your application, and authorization controls what each user can do. Flask itself is minimal, but it supports extensions like Flask-Login (for session management) and Flask-JWT-Extended or Flask-HTTPAuth (for token-based auth) to simplify secure authentication.
Find elsewhere
🌐
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?

🌐
Readthedocs
flask-login.readthedocs.io
Flask-Login 0.7.0 documentation
To mark a session as fresh again, call the confirm_login function. The details of the cookie can be customized in the application settings. While the features above help secure your “Remember Me” token from cookie thieves, the session cookie is still vulnerable. Flask-Login includes session protection to help prevent your users’ sessions from being stolen.
🌐
OneUptime
oneuptime.com › home › blog › how to implement flask-login for authentication
How to Implement Flask-Login for Authentication
February 3, 2026 - Authentication is the gatekeeper of your application. Without it, anyone can access anything. Flask-Login makes implementing authentication straightforward, handling the tedious session management so you can focus on building features. This guide walks you through setting up Flask-Login from scratch.
🌐
Miguel Grinberg
blog.miguelgrinberg.com › post › how-secure-is-the-flask-user-session
How Secure Is The Flask User Session? - miguelgrinberg.com
April 4, 2016 - Many times I hear people say that user sessions in Flask are encrypted, so it is safe to write private information in them. Sadly, this is a misconception that can have catastrophic consequences for…
🌐
OneUptime
oneuptime.com › home › blog › how to implement authentication in flask
How to Implement Authentication in Flask
February 2, 2026 - Flask-Login handles the session management side of authentication. It tracks which user is logged in, manages the "remember me" functionality, and protects views from unauthenticated access.
🌐
Stackademic
blog.stackademic.com › from-login-to-logout-mastering-secure-session-management-with-flask-login-and-sqlalchemy-09a1153ac239
From Login to Logout: Mastering Secure Session Management with Flask-Login and SQLAlchemy | by Prajwal Ahluwalia | Stackademic
October 20, 2025 - Enhanced Security Using server-side session storage reduces the risk of client-side tampering. Coupled with hashed passwords and secure cookies, this approach significantly strengthens security. User-Friendly Experience Flask-Login allows seamless session persistence, ensuring that users remain logged in until they log out or their session expires.
🌐
Scribd
scribd.com › document › 899242528 › Flask-Auth-Best-Practices
Flask Authentication Security Guide | PDF
This guide outlines best practices for secure authentication in Flask applications, emphasizing the use of Flask-Login for session management, password hashing, and CSRF protection. It also recommends enforcing strong passwords, enabling email verification, and implementing login attempt limits to prevent brute force attacks. Additionally, it advises using HTTPS, keeping dependencies updated, logging suspicious activity, and regularly backing up databases to ensure security and reliability. ... We take content rights seriously. If you suspect this is your content, claim it here.
🌐
Readthedocs
flask-security-too.readthedocs.io
Welcome to Flask-Security — Flask-Security 5.8.1 documentation
Flask-Security allows you to quickly add common security mechanisms to your Flask application. They include: Authentication (via session, Basic HTTP, or token) ... Social Login (OAuth) for authentication (e.g.
🌐
SitePoint
sitepoint.com › blog › programming › how to perform user authentication with flask-login
How to Perform User Authentication with Flask-Login — SitePoint
January 12, 2024 - Flask offers a variety of functions ... By making use of these functions, you can implement a robust and secure authentication system tailored to the specific needs of your application....
🌐
Readthedocs
flask-security-too.readthedocs.io › en › stable › features.html
Features — Flask-Security 5.8.1 documentation
Flask-Security allows you to quickly add common security mechanisms to your Flask application. They include: Session based authentication is fulfilled entirely by the Flask-Login extension.
🌐
Nucamp
nucamp.co › blog › coding-bootcamp-back-end-with-python-and-sql-securing-your-flask-web-application
Securing Your Flask Web Application - Nucamp Bootcamp
April 9, 2024 - HTTPS doesn't just hide your data; it protects it from those pesky man-in-the-middle attacks that try to snoop on your stuff. When it comes to user management and session integrity, Flask-Login is your best friend.
🌐
WAi Forward
waiforward.co.uk › blog › post › how-to-develop-a-secure-login-system-with-flask-and-python
How to Develop a Secure Login System with Flask and Python
That flexibility is ideal when you want clear control over security decisions such as hashing algorithms, session policies, and database models. Lightweight and Flexible: Allows for easy customization. Security Features: Supports password hashing, session management, and authentication. Integration with Databases: Works well with SQLite, PostgreSQL, and MySQL. Before getting started, install the required libraries: pip install flask flask-sqlalchemy flask-login werkzeug