Build Node.js User Authentication - Password Login

Поделиться
HTML-код
  • Опубликовано: 10 окт 2024
  • In this video we are going to build a secure Node.js user authentication system. I will be covering all of the security concerns that you will run into while building an authentication system. We will also cover how to securely store a password in case of a database breach. Lastly, we will cover how to login a user securely based on their name and password.
    📚 Materials/References:
    GitHub Code: github.com/Web...
    Login With Passport Tutorial: • Node.js Passport Login...
    🧠 Concepts Covered:
    What a password salt is
    How to properly hash a password
    How to store passwords
    Basic express server setup
    User login
    🌎 Find Me Here:
    Patreon: / webdevsimplified
    Twitter: / devsimplified
    Discord: / discord
    GitHub: github.com/Web...
    CodePen: codepen.io/Web...
    #WebDevelopment #WDS #JavaScript

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

  • @WebDevSimplified
    @WebDevSimplified  4 года назад +54

    Full Node.js application authentication tutorial: ruclips.net/video/-RCnNyD0L-s/видео.html

  • @TheOneHandedCooksman
    @TheOneHandedCooksman 2 года назад +46

    A little tip for those using Postman!
    If you're trying to send a request in postman and you're getting undefined or type errors, you're most likely trying to send params when you should be sending JSON in the body.
    instead of using 'Params', select 'Body', select the radio button 'raw', then at the right side of the radio buttons (next to 'GraphQL'), select JSON in the drop down. You're welcome.

  • @jimhalpert9803
    @jimhalpert9803 4 года назад +66

    This guy's teaching style is perfect.

  • @TheChodex
    @TheChodex 5 лет назад +59

    I feel like i discovered a gem on RUclips! Keep up the amazing work!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +6

      Thanks! I am really glad you like my video that much. Hopefully I do not disappoint in the future.

    • @AnuragSingh-ev8qd
      @AnuragSingh-ev8qd 7 месяцев назад

      Watching these videos in 2024 where AI is taking over Web Dev, still keeps me motivated and interested on becoming a Full stack real quick. Thanks for your efforts 🙌​@@WebDevSimplified

  • @hanswurst9900
    @hanswurst9900 5 лет назад +40

    Great video. Pretty simple and well explained.
    One thing: When authenticating with username/pw do not let the user know if a username does not exist. This way it is possible to create tons of requests to get all the stored usernames. Just respond with something like 'authentication failed' for either scenario (username not found / wrong pw).
    Keep up the good work!

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +25

      That is a good point. It also prevents people from discovering other people's usernames

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

      Can you explain how someone can create tons of requests to get all the stored usernames ?

    • @cyberchef8344
      @cyberchef8344 Год назад +1

      @@nasrisami17He doesn’t actually mean “all”. He means you could find a lot of usernames by essentially compiling a massive list of usernames beforehand, sending the login request, and then checking to see if the error is “user does not exist” vs “failed login”. The latter tells you that there is an account with that username on the server. This doesn’t imply you would actually be able to access the account, but information leaks are generally not good to have.

  • @wolfgalax8204
    @wolfgalax8204 4 года назад +16

    @9:01 He says "Hassed Pashword"
    Putting in a little comedy with these high quality explanations. You are going to be 1M+ soon. Very good explanation Sir, loved it.

  • @antoinesader8216
    @antoinesader8216 3 года назад +3

    Hey there, thanks for simplifying the web.
    I have a small notice that I want to share
    When you searched for the user inside the users/login route you have this (user=> user.name = req.body.name) instead of (user=> user.name = =req.body.name)
    I am sure that you've done that accidentally but just notifying you for other watchers.
    Thanks again

  • @joeyvico
    @joeyvico 4 года назад +54

    Hi Kyle, great tutorial so congratulations for that. However I encountered a problem in your code that would manifest when adding more users to the users array. After adding a second user and checking if that user existed and therefor logged in, this very process would overwrite its previous hashed password. Where the problem lies: in the route /users/login you check if user existed in the const user = users.find(user => user.name = req.body.name). You are using an assignment here instead of a comparison operator ==, it should be users.find(user => user.name == req.body.name). Hope this was helpful for others who may have tried adding more users to the array. Keep it up Kyle!! Best regards

    • @pranjalagarwal42
      @pranjalagarwal42 4 года назад +4

      This is what I am looking for

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

      Would love to see this process integrated with a database instead of an array, and with JWT. Basically a wholesome login. But for what it is, brilliant video Kyle

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

      @Kayle Excellent job! @Joey you are absolutely right, that's where it will be found a bug -:)

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

      great that you find the tutorial great, maybe someone of you can explain why we hashed a password, but did nothing with that password in the login function?
      As of right now, I found the tutorial more confusing than anything.

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

      @@AndrewTSq The hashed password was compared with the login request password

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

    im watching yt/udemy tutorials for past week. and i have to tell that you are the best that is out there. perfect pace, perfect voice, perfect explanation.
    big thank you!

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

      Thank you so much! That really means a lot to me and I am so glad that my teaching style resonates with you so well.

  • @nsharma4981
    @nsharma4981 4 года назад +10

    I can trust this channel blindly 😊 Authentication sounded really intimidating to me until now, but you simplified the basics soo well in such a short time! Really enjoyed the video. Thanks a lot, Kyle!

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

    We are working on a group project in the bootcamp I’m in and I’m handling the login page. This video is a godsend. Thank you

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

    that was PERFECT! i thought login was some complicated long process, this was a relief!
    although i know there is more to it than just this like jwt tokens and secure headers, oauth, 2 step auth etc. this was such a nice video to begin with

  • @adityajain5135
    @adityajain5135 4 года назад +23

    Complete and to the point. Awesome tutorial.
    Just a minor correction. In 'users/login' the users.find should use '==' and not '='. i.e. "users.find(user => user.name == req.body.name);" Else it would assign instead of comparing.

    • @user5214
      @user5214 2 года назад +1

      I know it probably doesn't matter, no, definitely doesn't, but he made a note of it in the video at timestamp: 11:18.

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

      Thanks man, I guess I missed seeing that note

    • @jhossepmartinez1771
      @jhossepmartinez1771 8 месяцев назад

      it does matter, it only works for the first user/time@@user5214

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

    whenever i get stuck on something, i always check your channel, knowing that i will find my answer..
    as always, i get what i need.. thank you kyle..

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

    Simple, fast, clear... you neeed to make more tutorials for us man, for eeverything, tutorials for life!

  • @jovannovakovic5975
    @jovannovakovic5975 5 лет назад +21

    Yes, we want full application!
    Thank you

  • @botdamian5688
    @botdamian5688 4 года назад +7

    The REST extension is a blessing :O I love it so much :O thank you

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

      could you tell me where the send request button is

  • @HowdyJ
    @HowdyJ 3 года назад +7

    I am revisiting some old concepts for a code test, and this tutorial was great. Just want to say, you have a super clean delivery, and your example flow is extremely good. I appreciate the new plugin for VSCode btw, the REST Client? Super dope. Anyway I'm only half way through and felt like I should sub, and let you know it was good quality content. Back to it!

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

    I am always excited when a new video goes up! You have helped me switch from being a UX Designer to JS Developer :) Greatly appreciate your work.

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

      That's awesome! I'm really glad I could help you along the way.

    • @ahmedb.r2098
      @ahmedb.r2098 2 года назад

      @@WebDevSimplified can we do that with websites

    • @ahmedb.r2098
      @ahmedb.r2098 2 года назад

      In html

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

    I was confused when salt was displayed with hashed password. After googling it I was surprised even more, actually its intended that way. Salt is used to protect from rainbow tables, not from brute force or dictionary attacks. For those you use peppers! As always great video Kyle, thx for upload!

  • @muhammadqasim6779
    @muhammadqasim6779 8 месяцев назад

    Thanks for such an easy and step by step guide, really easy to follow and understand, i watched many other tutorials which were 1 hour long and you just nailed it in 13 mins, Dude u are a gem

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

    I like the way you explain without a lot of blah blah. thank you!

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

    this is so clear, we beginners need this kind of video to teach very small thing one by one, thank you so much

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

    Excellent introduction for how to start with a node.js back end, makes it very easy to understand basic operations. Kudos!

  • @ShinSpiegel
    @ShinSpiegel 5 лет назад +143

    I would love to see a simple application with login

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +33

      I will make sure to make that one of my next projects.

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

      Up

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

      yeh, me too, desire for a simple real world application !!!

    • @inziderx8648
      @inziderx8648 4 года назад +8

      @@WebDevSimplified Please do a Auth boiler plate with MongoDB(Atlas): including passport, bcrypt and JWT. Having them in separate module is nice but having a complete boiler plate would be better. Love the 123 approach - keep the good work.

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

      This is a login and register system from WDS :)
      ruclips.net/video/-RCnNyD0L-s/видео.html

  • @MuhammadUsman-rp3ph
    @MuhammadUsman-rp3ph 4 года назад +21

    if someone faces errors with bcrypt.. try using bcryptjs having same functionalities
    npm install bcryptjs

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

      thx

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

      Or you could follow the instructions for your OS... Most likely missing either node-gyp or build tools, see: github.com/kelektiv/node.bcrypt.js#dependencies

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

    Thanks man! I miss doing backend with node.js and middleware stuffs. Will watch your channel often so I can still keep up in node. Great work!

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

    Short, Sweet and to the point tutorials. All videos are best Kyle.

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

    This was so helpful. Please make a longer, more in depth version with an app.

  • @yeTun-c5o
    @yeTun-c5o Год назад

    I been searching this for a month
    Now your explanation is so simple 13:31

  • @mustafayavuzgenel3623
    @mustafayavuzgenel3623 4 года назад +5

    These tutorials are awesome! Thank you so much for providing such a simple and well-explained tutorial. Keep up the good work! Can't wait for your other videos

  • @edgarb.2010
    @edgarb.2010 2 года назад +1

    In order to create unique users, add the following to the app.post route ('/users')
    const user = users.find(user => user.name == req.body.name)
    if ( user ) {
    return res.status(400).send('Already exists')
    }
    This will check if the name is already there and stop from being created, just something to keep in mind when implementing in production which usually uses usernames and emails versus name which can have duplicates.

  • @md.hasanmahmudrimon9867
    @md.hasanmahmudrimon9867 2 года назад

    followed you from a CSS battle you had with Powell... i think pursuing you was not bad. Thank you for your tutorials

  • @kunal5344
    @kunal5344 4 года назад +6

    The way he says "WHOOPS" gets me. Idk why, it just does.

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

    Super nice and quick! Shows the minimum amount so I can get a grasp on it and doesn't waste my time! Thank you very much. Great first step into this.

  • @Byomakesh1
    @Byomakesh1 Год назад +1

    That's pretty crisp & clear. Thanks a lot!

  • @kemal_ozturk
    @kemal_ozturk 5 лет назад +8

    Thank you for the tutorial! I laughed a lot every time you said "Hassed Pashword" :D

    • @WebDevSimplified
      @WebDevSimplified  5 лет назад +5

      Speaking and typing is way too much for my brain :P

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

    Awesome tutorials! Just checked out the entire web app authentication playlist. Found everything I was looking for in one place. Thank you Kyle.
    Subscribed! :)

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

    Your videos are pure gold due to very clean and precised form of providing information.
    Its great to have videos with pure information content with decent amount of energy.
    Thanks!

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

    berkcan güven.. kendini geliştirmiş yazılım işine atılmış helal olsun..

  • @bbosc674
    @bbosc674 Год назад +1

    Very simply explained! Thanks

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

    I'm going to recommend this channel to all my mates.. We're blessed to have you Sir..

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

    Simple easy and straight forward .. this is how teaching should be

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

    I have been working on this for a couple of hours and you made it so so simple. Lol. Thank you.

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

    Wow! Greetings from Brazil! Thank you for sharing this! I'm creating an Budget generator system with Node and React and this video help me out to implement secure passwords and login system on my application (I'm studying by myself, so I use hard Yotube and EAD platforms). Keep this awesome work and quality videos!

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

    Damn I love your vids, straight to the point, well done and thank you.

  • @jofawole
    @jofawole 10 месяцев назад

    thanks for this, man. My Node skill just got better!

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

    So crisp and to the point tutorial... I really like the way you explained.... Thank you 🙏

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

    Your concepts are really clear. Thanks and best of luck to you 🧡

  • @shivanshuhere
    @shivanshuhere 6 месяцев назад

    smoothly explained , loved it

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

    when am stuck you always come through, thanks

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

    I learnt everything about *SIMPLE AUTH*. Thanks a lot!!!

  • @TheAsianKidxD
    @TheAsianKidxD 3 месяца назад

    Web Dev Simplified! Stays very true to the name!!!

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

    This was so useful, you helped me go throughout my interview code challenge. You saved my life. Thanks

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

    I was able to learn user authentication through your video. Thank you.

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

    Thank you! This was very informative! Apart of the content you used, I also discovered that REST plugin for vscode is quite handy!

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

    Amazing video ❤
    I m just starting with backend and this is like the perfect guide for starting in it.
    Thanks alot man.

  • @eneomaos33
    @eneomaos33 Год назад +1

    Works! Thank you!

  • @eugenionita8702
    @eugenionita8702 2 месяца назад

    Subscribed, thank you for quality videos straight forward, Thanks 🙏🏼

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

    This is so amazing, so incredibly new experience, I learnt a lot of things along with authentication like that rest client, it is so easy and quick.
    Thankyou ♥️

  • @millionmeseret852
    @millionmeseret852 Месяц назад

    greate I like the way you build every thing from the scratch thanks!

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

    thank you such a awesome teacher. I read in the comments below that you are looking to make a full stack video for auth, wherein we sign in etc from a client app. Plz make it possible sn . thank you

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

    Hey great video! Very easy to understand and follow. I wonder did you ever make a full app that implements all of this?

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

    I will check out your other auth tutorials. Would love to see this with an actual database connection...mysql for example. Thank you as this was a great tutorial.

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

    Return value Array.find() is
    value of the first element in the array that satisfies the provided testing function. Otherwise, undefined is returned.
    Undefined not null

  • @dactal4444
    @dactal4444 Год назад +1

    the goat.

  • @webtutorials4279
    @webtutorials4279 3 месяца назад

    Simply life-saving !

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

    Great video Kyle!

  • @gokulkrishna.s5691
    @gokulkrishna.s5691 2 года назад +1

    Good teaching bro👋👋

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

    Thank for for this amazing tutorial. Finally undterstood the bcrypt npm! was so hard for me.

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

    great tip about rest client!

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

    You are very good at explaining.

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

    You're a fantastic tutor dude, thanks for all your work.

  • @sonamohialdin3376
    @sonamohialdin3376 Год назад +1

    Awesome tutorial thank you

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

    Thank you Kyle. You are the best. Keep up the good work.

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

    why do you shine? amazing courses man

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

    Absolutely concise and to the point, amazing. Thank you, that was tremendously useful.

    • @Earl-c4y
      @Earl-c4y Год назад

      I know what you mean. Some teachers talk a lot about nothing and the learning takes forever. He was just right, explaining what needed to be explained.

  • @allaguiamira8866
    @allaguiamira8866 Год назад +1

    very helpfull tutorial thank you

  • @Justin-cg4ot
    @Justin-cg4ot 3 года назад

    Great pace. Thanks for the content!

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

    Fala meu camarada, sou brasileiro, nao falo ingles, mas o seu video foi o que realmente me ajudou !!!

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

    Wow you explained simply

  • @aravind.a
    @aravind.a 3 года назад

    Your videos are eye opener.. thank you bro

  • @rohanvohra3434
    @rohanvohra3434 5 месяцев назад

    Awesome Content Liked the way you Explained

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

    Wow!! incredible ... Would love to see admin tutorial on existing non admin based app

  • @gandalfthegrey2777
    @gandalfthegrey2777 Год назад +1

    Hey I am getting an error in the login Post request, I've done everything same and tried everything but i constantly get 400 bad request error just on the /users/login Post route

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

    Neat and clear, Thank you WDS

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

    Just a heads up, you only used one equal sign in you find statement. meaning you will be redefining peoples user names.
    You want double equal sign when comparing, like this:
    const user = users.find(user => user.name == req.body.name)

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

    Shouldn't the line 25 on server.js read - const user = users.find(user => user.name === req.body.name) - rather than - const user = user.find(user => user.name = req.body.name) -. BTW, thanks a lot for these set of videos. They are amazing, keep up the good work.

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

    well done 👏 for a great video , looking forward to watch your upcoming one !

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

    Thank you very much. It was a great video. I would love to see a video of a full app with authentication as you mentioned at the end of this video. Thank you again! .

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

      I'm really glad you enjoyed it. I am looking forward to building a full app version of this.

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

      @@WebDevSimplified would be very nice, today im myself am going to try to put autentication in the full stack app, so users can see books and authors, but can only edit when logged in. I guess i should block parts of the routes depending on the login being true isn't it?

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

      That is correct. Using a library like passport to help you with this may be useful. You also can create a middle ware that will check if a user is logged in and make it return an error if they are not.

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

      @@WebDevSimplified Haha, fantastic, i got that working, it took a while, but that's the learning curve. its still needs some cleaning up, but that's for later, i just stored it at github.com/JEVBR/WDS

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

    Thank you very much from France!

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

    Thanks Robert Matthew Van Winkle, this was a great tutorial!

  • @MuhammadBilal-yw1fc
    @MuhammadBilal-yw1fc 2 года назад

    Simply You're more then everything for me, Best Wishes.

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

    Great tutorial, as always!

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

    I'm only 3 minutes into the video and you already got my like. I love the style of your explanations. Fast and concise so we get the maximum infos for minimum time. Really appreciated.

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

    Very clear explanation, thanks a lot !

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

    Your content is awesome bro👍👍👍

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

    Good short video. To the point. Is the method you described known as Basic Authentication ?

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

    Very clear and to the point. Thank you

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

    thank you for such a great content!! amazing work! subscribed!!!