User Password Authentication | Node.js & Express Tutorials for Beginners

  Рет қаралды 39,634

Dave Gray

Dave Gray

Күн бұрын

Web Dev Roadmap for Beginners (Free!): bit.ly/DaveGrayWebDevRoadmap
Add user password authentication to your Node.js & Express app. In this tutorial, you will learn how to add user registration and authentication routes. We'll hash and salt passwords user passwords for safe storage, too.
🚩 Subscribe ➜ bit.ly/3nGHmNn
🚀 This lesson is part of an Node.js & Express for Beginners tutorial series playlist:
• Node.js Tutorials for ...
🔗 Starter Source Code: github.com/gitdagray/express_mvc
🔗 Completed Source Code: github.com/gitdagray/user_auth
User Password Authentication | Node.js & Express Tutorials for Beginners
(00:00) Intro
(00:05) Welcome
(00:32) Simulating a users database
(00:57) Two routes are needed
(01:09) Create the register controller
(03:00) Install bcrypt dependency
(04:07) Handle new user request
(07:55) Hash and Salt passwords with bcrypt
(12:34) Create the register route file
(13:50) Add the route to the server
(14:13) Start the dev server
(15:13) Test the register route
(18:21) Create the auth controller
(22:57) Create the auth route file
(23:43) Add the auth route to the server
(24:03) Test the auth route
📚 References:
Bcrypt: www.npmjs.com/package/bcrypt
How to Safely Store a Password: codahale.com/how-to-safely-st...
MDN: HTTP Response Status Codes: developer.mozilla.org/en-US/d...
📚 More References:
Node.js Official site: nodejs.org
NPM Official site: www.npmjs.com/
Express JS Official site: expressjs.com/
MDN CORS: developer.mozilla.org/en-US/d...
NPM CORS: www.npmjs.com/package/cors
✅ Follow Me:
Twitter: / yesdavidgray
LinkedIn: / davidagray
Blog: yesdavidgray.com
Reddit: / daveoneleven
Was this tutorial about user password authentication with Node.js and Express JS helpful? If so, please share. Let me know your thoughts in the comments.
#user #password #authentication

Пікірлер: 83
@mohammedasim6237
@mohammedasim6237 10 ай бұрын
Dave, I cannot express my gratitude in words. This course has everything. Thank you so much!
@Salma-qy3qb
@Salma-qy3qb 9 күн бұрын
I have this huge class project that I accidentally put off until the last 2 weeks before the discussion so i'm cramming your playlist in hopes it'll give me all I need to finish my project. And even though I'm a complete web dev beginner I can still follow along because of your way of explaining things you don't let any part slip you always refer to where it came from! Thank you so much :")
@Anbaraen
@Anbaraen 2 жыл бұрын
Keep it up Dave, learning a lot from you applying your signature comprehensive style to Express!
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you, and glad to hear it! 🙏💯
@shineLouisShine
@shineLouisShine Жыл бұрын
Knowing now much more then I did 8 months earlier (When I first saw this video), I came back to watch it, and I appreciate it a lot once again and even more... Thank you.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome!
@jamshidtashkent1976
@jamshidtashkent1976 Жыл бұрын
I have watched many videos in English about coding which were difficult to understand for me, but your pronunciation is very excellent, and easy to catch it. I appreciate your effort.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad it helped!
@ankitbhuria4554
@ankitbhuria4554 4 ай бұрын
Sir ! You are of the best tutors available for us on youtube :)
@ebesquin
@ebesquin Жыл бұрын
Dave: Thank you very much for this wonderful course. It is the best there is, especially for a clear explanation
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're very welcome!
@fares.abuali
@fares.abuali 2 жыл бұрын
This is so informative and entertaining. I can't thank you enough 🙏
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Fares!
@rameshgm81
@rameshgm81 3 ай бұрын
Thank you very much @DaveGrayTeachesCode. This course is awesome. I am a C++ developer having 2 decades of experience and now I have shifted my Gears towards Web Programming. You session has provided excellent confidence to me and I am able to design the MVC using MEAN stack. Thank you very much. I have subscribed to your channel and seeking your support for my career growth. :)
@filthynirvana5553
@filthynirvana5553 2 ай бұрын
great ! i hope that transition from C++ to JavaScript wasn't too rough.. that was my case at least haha. good luck, friend
@jellyfish1772
@jellyfish1772 Жыл бұрын
The only teacher who uses proper status codes!!!thank you sensei
@MohammadBarghamadii
@MohammadBarghamadii Жыл бұрын
Thanks so much, Dave; it is a valuable Node and express.js course for free.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome, Mohammad! 🙏💯
@shineLouisShine
@shineLouisShine Жыл бұрын
Thank you very much. In this lesson (such as the previous one) - Thunder Client doesn't respond to requests While the server runs on port 3500. It is just at status of endlessly "Processing...". It did work well in the Router lesson.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
I do not have that problem with my code here. There must be a difference in there somewhere.
@brydiginte6552
@brydiginte6552 Жыл бұрын
Really great tutorials, much appreciated!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Glad you like them!
@abdulrahmanagboolaosho3582
@abdulrahmanagboolaosho3582 Жыл бұрын
thank you so much sir, I have learnt most of what I know from you for free, you truly are an amazing person
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
You're welcome!
@mohitpunia6245
@mohitpunia6245 Жыл бұрын
very nice course ,i am learning nodejs first time, glad i come to this channel recommended by my boss
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Welcome aboard! And thanks to your boss for the recommendation!
8 ай бұрын
You re awesome Dave. Thank you so much for wonderful videos.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 8 ай бұрын
Thank you for the support!
@akotech79
@akotech79 10 ай бұрын
you just the best of the best, thank you very much.
@369-davian
@369-davian 2 жыл бұрын
Excellent now follow your channel muy respect from Dominican Republic
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you, Ricardo! 🙏
@ogundekoadegbenga3766
@ogundekoadegbenga3766 Жыл бұрын
Thanks Dave.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Welcome!
@sonamohialdin3376
@sonamohialdin3376 2 жыл бұрын
Amazing tutorial thank you
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you!
@tabliqatchi6696
@tabliqatchi6696 2 жыл бұрын
Perfect tutorial.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Glad it was helpful! 💯
@armanbulatovich7341
@armanbulatovich7341 2 жыл бұрын
u r very good teacher. thanks for video.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You're welcome, Arman 🙏💯
@user-sb9ve6zd6p
@user-sb9ve6zd6p Жыл бұрын
Спасибо большое Дэйв! Супер уроки! Очень хотелось бы PERN плэйлст
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you and thank you for the request!
@sheldon9968
@sheldon9968 Жыл бұрын
Thank you sir😀
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Most welcome!
@DeepakGupta-hj2dv
@DeepakGupta-hj2dv 2 жыл бұрын
Keep it up dave....excellent video ...please more video like Node JS microservices crash course
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thank you Deepak 🙏
@DeepakGupta-hj2dv
@DeepakGupta-hj2dv 2 жыл бұрын
This series is complete now ???
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
@@DeepakGupta-hj2dv not yet. Protecting routes with JWT is next followed by MongoDB integration.
@DeepakGupta-hj2dv
@DeepakGupta-hj2dv 2 жыл бұрын
@@DaveGrayTeachesCode okk more video rest api integration
@abdullahsevmez42
@abdullahsevmez42 2 жыл бұрын
if you add about google auth and facebook auth logic (how to store in database and how to manage session) this lecture it will be perfect :)
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Those are good additional lesson suggestions - thanks!
@nestlypay4617
@nestlypay4617 Жыл бұрын
Still waiting for this though, thanks dave.
@bardhan.abhirup
@bardhan.abhirup Жыл бұрын
Just something I noticed - around the 8:00 mark, you comment that you're about to encrypt the password and you go on to hash it. Aren't those two fundamentally different? Or am I missing something? Loving the tutorials!
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Thank you! Yes, the terminology overlaps a little. We're using the npm package bcrypt, but it does hash the password. Reference here, too: stackoverflow.com/questions/9035855/is-bcrypt-used-for-hashing-or-encryption-a-bit-of-confusion
@TheLucidway
@TheLucidway 2 жыл бұрын
Dave, how is it that we can work with the data from users.json without using JSON.parse()? Does require() already parse the strigified data?
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Good question. We didn't use JSON.stringify on the data in the json files either.. so JS just looks at that data as an array of objects when we import it.
@TheLucidway
@TheLucidway 2 жыл бұрын
@@DaveGrayTeachesCode Right on. Thanks for clarifying
@flammablepez
@flammablepez Жыл бұрын
Hi Dave! Wonderful tutorials as usual so thanks for that first and foremost. I'm having a little problem though in testing the duplicate user entry function. My api request just hangs and eventually times out. For some reason, it appears it doesn't like only trying to send a status response without any message? Once I added ".json({ message: `User ${user} already exists.` })" to the return statement following "res.status(409)" it works. Any idea why? Is it always necessary to send a response message of some sort with a status code?
@flammablepez
@flammablepez Жыл бұрын
After building the authController, I realize it appears we must use sendStatus instead of just status. :)
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Consider this from the docs: expressjs.com/en/5x/api.html#res.end
@mrrandom7920
@mrrandom7920 Жыл бұрын
Cool.
@motiurrahman8751
@motiurrahman8751 Жыл бұрын
Hi @Dave first of thank you very much for your tutorial series. i am having an issue. while i send a request for new user i get this error "Connection was forcibly closed by a peer." but on the users.jason file i can see the new user. why it is happening?
@ogundekoadegbenga3766
@ogundekoadegbenga3766 Жыл бұрын
Check your object key for username and password. I mistakenly spelt password as paswword and already registered a user. When I decided to authenticate, it threw the error same as yours. So I had to delete the content of users.json and checked my object keys spellings, if they are same as what I have passed in the logic for auth and register js files.
@ogundekoadegbenga3766
@ogundekoadegbenga3766 Жыл бұрын
In addition check the error message in console to trace the exact area the error is coming from, that's the file tree. Hope this helps
@satdm9721
@satdm9721 Жыл бұрын
Can you do a tutorial on how to secure routes and database production level
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
If you continue in this playlist, you should see how routes are secured for the backend. If you want secure routes for the frontend, checkout my React Auth playlist.
@satdm9721
@satdm9721 Жыл бұрын
@@DaveGrayTeachesCode Appreciated. I am just getting into dev and found your tutorials very helpful so far. Will continue down the line
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Many apps require user authorization. In this tutorial, we will create registration and authorization routes in Express and handle the necessary logic required to create new users and authenticate users once they exist. If you are new to Node & Express, I suggest starting at the beginning of this Node.js for Beginners playlist found here: kzbin.info/aero/PL0Zuz27SZ-6PFkIxaJ6Xx_X46avTM1aYw
@araphalim
@araphalim Жыл бұрын
Hey! When I deleted the employee 2 then created new employee, new employee id was added as 4, how can i make it fill in the id that been deleted??
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
Filling in a number that was deleted is not usually a good idea. It could possibly link to other things from the previous user account. Always create a new id.
@araphalim
@araphalim Жыл бұрын
@@DaveGrayTeachesCode I see! And WOW! Thanks for really quick reply!
@ramziosta
@ramziosta 2 жыл бұрын
my refresh token is not working. I keep getting 401 un authorized. I downloaded the git repo and added my .env file but same issue. I dont have any error in my terminal, and not sure where exactly to look
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
You may need to add secure: true in the authController when the cookie is issued in the Node.js code.
@ahmetkaya6168
@ahmetkaya6168 Жыл бұрын
Until now, we have created three routers (employees, register, and auth) rather than root. You put employees router in the api folder, but you did not put register and auth routers into api folder. It seems that they too seems api. Why did not you put them into api folder? I think your answer will make me clear regarding the definition of API.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
It is all in how to you choose to set up your routing. You can look ahead in the course resources and see that I create routers for all of the main routes, but I chose to make an api directory for the routes that provide data - both users and employees. github.com/gitdagray/mongo_async_crud/tree/main/routes
@elAmigo805
@elAmigo805 Жыл бұрын
I'm getting this strange error that I can't locate: [nodemon] starting `node server.js` C:\Projects\Dave Gray\BackendServerTuts\ExpressTutorial\UserPasswordAuth ode_modules\express\lib outer\index.js:502 this.stack.push(layer); ^ TypeError: Cannot read property 'push' of undefined at Function.route (C:\Projects\Dave Gray\BackendServerTuts\ExpressTutorial\UserPasswordAuth ode_modules\express\lib outer\index.js:502:14) at Function.proto. [as post] (C:\Projects\Dave Gray\BackendServerTuts\ExpressTutorial\UserPasswordAuth ode_modules\express\lib outer\index.js:509:22) at Object. (C:\Projects\Dave Gray\BackendServerTuts\ExpressTutorial\UserPasswordAuth outes egister.js:5:8) at Module._compile (internal/modules/cjs/loader.js:1063:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10) at Module.load (internal/modules/cjs/loader.js:928:32) at Function.Module._load (internal/modules/cjs/loader.js:769:14) at Module.require (internal/modules/cjs/loader.js:952:19) at require (internal/modules/cjs/helpers.js:88:18) at Object. (C:\Projects\Dave Gray\BackendServerTuts\ExpressTutorial\UserPasswordAuth\server.js:28:22) [nodemon] app crashed - waiting for file changes before starting... Anyone have an idea how to fix? It happed at 15:13 when initially starting the server for this video.
@DaveGrayTeachesCode
@DaveGrayTeachesCode Жыл бұрын
The error happens in your code here: server.js:28:22 ..which means line 28 at character 22. And "TypeError: Cannot read property 'push' of undefined" means you are trying to use the "push" method on something that is undefined.
@alirezahekmati7632
@alirezahekmati7632 2 жыл бұрын
🚀
@soniablanche5672
@soniablanche5672 2 жыл бұрын
by the way there's a shorter way of writing a function inside an object { myFunction: function() { this.a = 1; } }; can be shortened to { myFunction() { this.a = 1; } };
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Good advice!
@TheNamesJT
@TheNamesJT 2 жыл бұрын
This video is very useful and all but, would of been better if you actually used a real database instead of just a json file. The reason being is that if someone is trying to learn User Password Authentication and watches this video its not even close to a production state they would need to change the code to work with their preferred database which means totally different syntax ect even if you showed in this video how to convert it to use mongodb or postgress ect would of been fine but from what i can tell you don't.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
Thanks for the comment. I will be introducing MongoDB in this series and replacing the dev JSON file... but I wanted to develop all Express routes first. Then the Mongo tutorials could be subbed for Postgres, MySQL or something else as well. Kind of like a book with chapters that build on each other.
@TheNamesJT
@TheNamesJT 2 жыл бұрын
@@DaveGrayTeachesCode O okay, I didn't know this was going to be a series usually the video is in a playlist or has a number associated with the series. Its looks like a one off video which is what led me to the feedback above. Anyways, i'm looking forward to this.
@DaveGrayTeachesCode
@DaveGrayTeachesCode 2 жыл бұрын
@@TheNamesJT no worries! Yes, still building out the Node.js & Express for Beginners. The goal is to cover the full MERN stack when combining this series with the React series. Thanks again for the comment!
JWT Authentication | Node JS and Express tutorials for Beginners
1:00:03
БОЛЬШОЙ ПЕТУШОК #shorts
00:21
Паша Осадчий
Рет қаралды 8 МЛН
THE POLICE TAKES ME! feat @PANDAGIRLOFFICIAL #shorts
00:31
PANDA BOI
Рет қаралды 24 МЛН
Build Node.js User Authentication - Password Login
13:31
Web Dev Simplified
Рет қаралды 509 М.
User Uploaded Images (Host For Free & Cloudinary Example Code)
20:06
Learn Express Middleware In 14 Minutes
14:48
Web Dev Simplified
Рет қаралды 389 М.
Intro to MongoDB and Mongoose | Node.js Tutorials for Beginners
17:06
Node.js Passport Login System Tutorial
36:28
Web Dev Simplified
Рет қаралды 1 МЛН
Choose a phone for your mom
0:20
ChooseGift
Рет қаралды 6 МЛН
Klavye İle Trafik Işığını Yönetmek #shorts
0:18
Osman Kabadayı
Рет қаралды 122 М.