Authentication and Authorization With Flask-Login

Поделиться
HTML-код
  • Опубликовано: 10 сен 2024

Комментарии • 103

  • @nonotezou3529
    @nonotezou3529 5 лет назад +38

    At 27:23, ur if " if not user and not check_password_hash(user.password, password)" will allow the user to login if the password is wrong, ti should be something like ' if not user OR not check_password_hash(user.password, password)'
    Because in ur case we have:
    - if the user doesnt exists, an error will be raised on the user.password
    - if the user exists then the first (not user) is set to false which wont listen to the second part because its an "and"

    • @prettyprinted
      @prettyprinted  5 лет назад +12

      You're absolutely right. Thanks for bringing it up.
      I confused myself with the logic and didn't notice.

    • @bhavyadhuria2032
      @bhavyadhuria2032 3 года назад

      Yeah I noticed that as well, basically there should be an 'or' instead of an 'and'

  • @prettyprinted
    @prettyprinted  4 года назад

    Join my free course on the basics of Flask-SQLAlchemy: prettyprinted.com/flasksql

  • @sgr2683
    @sgr2683 3 года назад +2

    🌟❗if you are facing error in running flask app.
    Use set in place of export command.
    As export is only valid for Unix shells.
    use set for windows.

  • @aekanshupanchal
    @aekanshupanchal 4 года назад

    Very nice tutorial it removes all confusion as i first seen video from two year back and now I have a better approch

  • @sohamnandi4708
    @sohamnandi4708 4 года назад +2

    how to run the app ?? my flask run is not working it there not a way to run it from python app.py

  • @sergeykapshuchenko5695
    @sergeykapshuchenko5695 5 лет назад +4

    pls, explain how to run this app
    how to run it from a py file, not from project folder ?
    because I can not deploy it on Heroku

  • @constantinewesterink3845
    @constantinewesterink3845 3 года назад +1

    When i run "from project import db, create_app" in the terminal it send me this error:
    File "", line 1, in
    File "project/__init__.py", line 1, in
    from flask import Flask
    ImportError: No module named flask
    How do i fix this?

  • @HedgarBezerra
    @HedgarBezerra 5 лет назад +3

    I just wish you had 10kk subs, you deserve, your vids are lit

  • @fredcode89
    @fredcode89 4 года назад

    thanks for your video.... now i finally understand user authentication and login in flask

  • @utipocolindo
    @utipocolindo 5 лет назад

    Thank you, this came at the right time, when I need to study authorization and authentication for future implementations in my work. Even though it is simple, it helps to have a notion for more complex implementations.

    • @prettyprinted
      @prettyprinted  5 лет назад +1

      Glad it helped. Make sure you note the correction in this comment thread (at 27:23).

  • @jafd7806
    @jafd7806 4 года назад +1

    With this video and the token jwt one, you earned my sub bro, keep it up

  • @gaborf3168
    @gaborf3168 4 года назад

    Too bad I cannot double like this video. You are my hero.

  • @birindwagrace3287
    @birindwagrace3287 4 года назад +3

    Hi, when i try to run a got this error: flask.cli.NoAppException: Could not import "flaskLogin.flaskLogin". cause my project name is flaskLogin, i've runed export FLASK_APP=flaskLogin

    • @jerrychian
      @jerrychian 4 года назад

      it might cause your project name conflict with flasklogin package?

  • @yogeshwarangovindarajan8817
    @yogeshwarangovindarajan8817 4 года назад +1

    how to download your code from github?

  • @taylorjewell5038
    @taylorjewell5038 4 года назад +1

    where is the create_app function called?

  • @bryanzhu9568
    @bryanzhu9568 4 года назад

    This is some great stuff, hope you keep making more.

  • @yashchhatre7339
    @yashchhatre7339 4 года назад +1

    Hey man I am super late, but I had a question everytime I try to import something through terminal it doesn't work. For example, you said to "from project import db", however my thing tells me a module named db doesn't exist. any ideas on how to solve?

    • @AnkurSingh-mk9rc
      @AnkurSingh-mk9rc 4 года назад

      maybe type python before using python commands

  • @brianng830
    @brianng830 4 года назад

    Anybody get 'flask login module not found' error during Heroku Deployment?

  • @azigarimbata2625
    @azigarimbata2625 4 года назад

    Brother, simply you're the best!

  • @DilipCM1777
    @DilipCM1777 3 года назад

    thanks for a nice video. But I've a query that i build an ecommerce wesite and when a specific_user adds items to cart it also displays in the other users of the database table.how to resolve it?.Any help is heartfully accepted..

  • @yamkelakutu5707
    @yamkelakutu5707 4 года назад

    This is awesome - thanks man for an amazing video 👌🏾

  • @makedifference4548
    @makedifference4548 2 года назад

    is was great learning.. do you have video where user is added by admin and need to login with correct credential provided by admin. later on where user can reset the password

  • @sarojrai8716
    @sarojrai8716 4 года назад +1

    kindly provide github source code link for the same

  • @iKunj026
    @iKunj026 2 года назад

    Hi,
    How can i deploy this page using heroku
    And gunicorn ?

  • @cloppingemu1471
    @cloppingemu1471 4 года назад

    Hi isn't this authentication flawed? You are sending password to the server in plain-text (over https but if https fails due to certification fuckery or man in the middle, you have plain text) and hashing the password on the server side (although you would salt it on the server before storage so it that is just specifications we skip for simplification). Once you have access to the post, you can just extract the password or send the same post again. Having said that, I understand if you had the post, you would still be able to authenticate if the password was hashed on the client side. So is there anything that could would withstand a SSL failure (man in the middle is difficult to beat) but would not require implementing PGP in javascript + python?

  • @baumjohannable
    @baumjohannable 3 года назад

    Is it save to send your password in plain text like this in form that is being pushed?

  • @saifuddinabdullah7286
    @saifuddinabdullah7286 4 года назад

    Super helpful! Thank you so much.

  • @abrarahmed7549
    @abrarahmed7549 4 года назад

    Hello Anthony..
    Flask security login not working with nginx server

  • @amazingproductsoftheintern3516
    @amazingproductsoftheintern3516 5 лет назад

    Just what i was looking for Thanks!!!!! You are awesome

  • @DanOhCaptainDaniel
    @DanOhCaptainDaniel Год назад

    how did you do the css for this, where can I find this in your github?

  • @kengku1234
    @kengku1234 5 лет назад

    Hi
    It's a good video it's teach me to basic flask.Thank you very much ♥

  • @siddheshshivgan6870
    @siddheshshivgan6870 4 года назад

    Thanks man, This helped a lot!!

  • @vinsmokearifka
    @vinsmokearifka 5 лет назад

    Thank you Anthony. Thats what i need..

  • @sunlord0327
    @sunlord0327 4 года назад

    For mine, it says that the object 'User' has no attribute 'query'

  • @niwanshumaheshwari4534
    @niwanshumaheshwari4534 4 года назад

    i get internal error 500 when i click on signup button a , please someone help

  • @joao_matos
    @joao_matos 4 года назад +1

    Hi, thank you for this tutorial. I'm trying to build a login page with an username, password and department fields.
    The app has an User and Department model.
    Now it needs to know each department the user logged into, for it to be able to render the right template, etc...
    I've tried storing it in the g variable, using context processors but it did not work as I expected.
    I needed something like the flask-login package where I would have current_department and be able to access this value from a template or a view function. How should I do this?

    • @stentechy3346
      @stentechy3346 2 года назад

      why didn't you use a DB(use a query/function that checks for user-department relation) or or store user-department in flask sessions.

  • @superuser8636
    @superuser8636 3 года назад

    Cool video, thanks. At 5:55 you don’t need to comment out the code; Python is cool so, skip, just do
    def login_pos():
    pass

  • @FabiVoltair
    @FabiVoltair 5 лет назад

    Awesome Tutorial man! Thank you a lot!

  • @kalun_gaming
    @kalun_gaming 5 лет назад +1

    Hi Anthony,
    First of all, this is a great video. I do have a query though that in your auth.py at 28:02 Line 16 it says "if not user and not check_password_hash:"
    should it be or instead of and because and would need the both of the conditions to be true to execute the function inside the if statement?

    • @prettyprinted
      @prettyprinted  5 лет назад +2

      Yes, it should be an or instead. My mistake.

  • @eidiazcas
    @eidiazcas 5 лет назад

    Does this generate a token? and if so how do I get it? I need it for an API

  • @rasimatics
    @rasimatics 4 года назад

    Thank you very much :)

  • @agustinmaletti868
    @agustinmaletti868 5 лет назад

    thanks you, you are very clear!

  • @muhammadammad330
    @muhammadammad330 Год назад

    Do you have any video on role base authorization in flask?

  • @sushaanpatel1337
    @sushaanpatel1337 3 года назад

    damn this dude helped me alot

  • @karlduckett
    @karlduckett 5 лет назад

    Wow! That was awesome!
    Can I request a part 2 where email validation is used on this same framework :)
    Thank you so much!

    • @prettyprinted
      @prettyprinted  5 лет назад

      I'll consider a video on email validation. Thanks for the idea!

  • @DilipCM1777
    @DilipCM1777 4 года назад

    nice video sir..could u be able to make video on how to authenticate multiple users using loginmanager and flask-bluprints

  • @vijaybabaria3253
    @vijaybabaria3253 4 года назад

    Thanks for sharing, would it be possible to add Google and Facebook login?

  • @jonasherseth5306
    @jonasherseth5306 5 лет назад

    Didn't find the Scotch.io link here, so went out and looked for it: scotch.io/tutorials/authentication-and-authorization-with-flask-login

  • @jashjasani5045
    @jashjasani5045 4 года назад

    Hey Anthony, I really love your videos and they have cleared a lot of concepts for me! Can you please help me with the same task using PostgreSQL as the database?

  • @dcard729
    @dcard729 4 года назад

    login?next=%2Fprofile -
    Is it safe??

  • @lucasgomez3531
    @lucasgomez3531 4 года назад

    One question: How should I run this app if I am using pipenv as environment?

    • @lucasgomez3531
      @lucasgomez3531 4 года назад

      solved it: I just added a .flaskenv with this code FLASK_APP=.

  • @BrianOstrovsky1
    @BrianOstrovsky1 5 лет назад

    This was good but I was wondering if there is anyway to set roles or permissions. I like Flask-Login as it is easy but Flask_User has authorization levels. Can I get authorization levels or permissions out of Flask-Login?

    • @prettyprinted
      @prettyprinted  5 лет назад

      You'd have to make them yourself. But Flask-Security might work for you because it's based on Flask-Login but it doesn't give you actual pages like Flask-User.

  • @cedrickiplimo2991
    @cedrickiplimo2991 3 года назад

    @Pretty Printed, if you don't mind, could you do a quick tutorial on how to perform authentication where you have multiple models. Maybe something like Student and Staff

    • @samrathchadha5062
      @samrathchadha5062 3 года назад +1

      I think you could make a separate login page.

    • @cedrickiplimo2991
      @cedrickiplimo2991 3 года назад +1

      @@samrathchadha5062 Yeah. I figured. It's good practice, apparently, to have a separate auth table. Saved me lots of trouble.

  • @MatsumotoKael13
    @MatsumotoKael13 4 года назад +1

    Hi there!
    I realise nobody will care about this unless you speak German, but it drove me crazy the entire video everytime you said "virkzirg" instead of WERKZEUG.
    In case you're interested:
    the pronunciation of "Werkzeug" is as follows:
    the "w" sounds like the "v" in "victory"
    the "er" sounds like the "arr" in "arrow"
    the "k" is basically like the english k
    the "z" is like english "ts"
    the "eu" sounds like the "oi" in "point"
    the "g" is like the "g" in "get"
    Or you can use this for reference:
    forvo.com/word/werkzeug/
    Werkzeug is the German word meaning roughly something like "Tool" or "Toolkit".

  • @Lhistoire_a_table
    @Lhistoire_a_table 5 лет назад

    hello Sear, i follow your tuto, it's a great thing for me to lear flask. but i can't find the file base.html. can you give the link please of this file. thanks alot

    • @prettyprinted
      @prettyprinted  5 лет назад +1

      I'm using Flask-Bootstrap for the base. If you want to modify it, you have to override with your own.

  • @ellasherilynramos9600
    @ellasherilynramos9600 5 лет назад

    Would this actually be okay to use alone in Production? Like this is all the security an app has?

    • @prettyprinted
      @prettyprinted  5 лет назад

      For a basic app it's fine. For apps where you expect more users, you may want to consider focusing more on security. Security depends more on what your use cases is and not some checklist of things to do.

  • @000djw000
    @000djw000 3 года назад

    Really nice video, but I keep thinking Kermit is teaching me python! :-)

  • @jtakajm1b
    @jtakajm1b 5 лет назад

    Great vid man. In my case im trying to restrict api access based on user permissions. I'd like to know how that could be done with maybe flask_principle? Also why flask_login and not flask_jwt?

    • @prettyprinted
      @prettyprinted  5 лет назад

      If you have an API the authentication will be different from this video. Check out my API auth video with JWT.

  • @ikhsanrahman9703
    @ikhsanrahman9703 4 года назад

    how to use jwt with flask login ?

  • @karangujrati679
    @karangujrati679 5 лет назад

    Hey Anthony, I really love your videos and they have cleared a lot of concepts for me! Can you please help me with the same task using MongoDB as the database?

    • @prettyprinted
      @prettyprinted  5 лет назад

      Maybe this video will help: ruclips.net/video/vVx1737auSE/видео.html

  • @MrFyce
    @MrFyce 3 года назад

    how about signup?

  • @mattiznielsen6901
    @mattiznielsen6901 5 лет назад

    Hey!
    How do I get rid of "/login?next=%2Fprofile"?

    • @prettyprinted
      @prettyprinted  5 лет назад

      You'll have to create your own unauthorized callback: flask-login.readthedocs.io/en/latest/#flask_login.LoginManager.unauthorized_handler

  • @islahulkhozani5858
    @islahulkhozani5858 4 года назад

    so cool

  • @jitendra2510
    @jitendra2510 5 лет назад +1

    Clean

  • @sirguroz
    @sirguroz Год назад

    Registration no?

  • @mattiznielsen6901
    @mattiznielsen6901 5 лет назад

    Are you going to publish the code on github?

    • @prettyprinted
      @prettyprinted  5 лет назад

      Within a few days when I publish the article on Scotch.io.

  • @AshokKumar-fo5gw
    @AshokKumar-fo5gw 4 года назад

    where is authorization in this example?

    • @prettyprinted
      @prettyprinted  4 года назад

      It's just the login_required part, which is the simplest authorization you could have. It can easily be extended to more checks on what type of user is authorized to do what actions.

  • @abdelazizsharaf7305
    @abdelazizsharaf7305 4 года назад

    Greet thanks is actually not enough

  • @C__Tarek
    @C__Tarek 5 лет назад

    'load_user' given an errors : User has no attribute 'query'

    • @prettyprinted
      @prettyprinted  5 лет назад

      Make sure your User class is using Flask-SQLAlchemy.

  • @rafarakowskidzonybt60
    @rafarakowskidzonybt60 2 года назад

    There is only authentication, authorization is not.

  • @sumeetsharma4283
    @sumeetsharma4283 2 года назад

    Hard to follow

  • @samargndi
    @samargndi 3 года назад

    man you said authentication and AUTHORIZATION and there is nothing about authorization.