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 OverflowFlask-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.
Flask-Security-Too, while it can be complex if you try to use all of its features, proves to actually be pretty easy to set up production-ready applications. It is actively maintained. I have a few working projects in production using this library (v4.x.x). Not too long ago, there has been a v5.x.x release as well.
You should definitely check that out.
- Flask-Security-Too: https://flask-security-too.readthedocs.io/
- My Example Application: https://github.com/hrishikeshrt/flask-bootstrap-anywhere
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.
the login process seems secure.
But you didn't check the potential existing user in the signup form, or existing email address. Unless this is managed by the underlying User schema.
And you should require a minimal password complexity. Danjgo does this by default but the passwordmeter package could help you to achieve this.
https://pypi.python.org/pypi/passwordmeter
It is vulnerable to account enumeration via timing attacks because you only do the bcrypt when the username exists. You can fix it by adding a dummy computation when the user does not exist. Not a major issue, but you should at least be aware of it.
Although you did well in choosing bcrypt, I agree with @glenfant that at least something should be done with password complexity. However, recommend having a read on NIST's new password guidelines. Don't follow traditional guidelines that annoy users.
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?
I think Flask-Security is deprecated right now. I never used Flask-User on a project. Flask-Login was always my choice for handling sessions/users. You can make your own session handler. I recommend using JWT for authentication & authorization.
I'd roll with Flask-Login (I've used it on many projects with great success and I would use it today on a new project).
It's pretty low level and really only controls the gory bits of ensuring a session is created and potentially persisted with cookies. Then on top of that it gives you access to the idea of having a current_user which is the logged in user and some decorators to ensure a user is logged in.
With Flask-Login you have free reign on how to design the flow and UI of your user registration / authentication system because all it does is handle authentication. Flask-Login also makes it really easy to pick a way that users would get authentication too (such as looking up a user in your database).
If you're worried about commit dates and projects dying, Flask-Login is your best because it's so focused on 1 thing. If you ever wanted to replace that, you could step in and drop in a replacement without having to change much of your code at all.