Skip to content

LashminiAD/authentication-system-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

3 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” Authentication System using Node.js

A secure Authentication System built using Node.js, Express.js, MongoDB, Mongoose, bcrypt, JWT, Cookies, and EJS.

This project demonstrates a complete authentication flow including user registration, login, password hashing, JWT authentication, cookie-based session handling, and protected routes.


๐Ÿš€ Features

  • User Registration (Sign Up)
  • User Login
  • Secure Password Hashing using bcrypt
  • JWT Token Authentication
  • Cookie-Based Session Handling
  • Protected Dashboard Route
  • Logout Functionality
  • MongoDB Database Integration
  • EJS Templating Engine
  • Simple Instagram-inspired UI

๐Ÿ› ๏ธ Tech Stack

Backend

  • Node.js
  • Express.js
  • MongoDB
  • Mongoose

Authentication & Security

  • bcrypt
  • JSON Web Token (JWT)
  • Cookie Parser

Frontend

  • HTML
  • CSS
  • EJS

Tools

  • Git
  • GitHub

๐Ÿ“‚ Project Structure

authentication-system-nodejs
โ”‚
โ”œโ”€โ”€ models
โ”‚   โ””โ”€โ”€ User.js
โ”‚
โ”œโ”€โ”€ public
โ”‚   โ””โ”€โ”€ style.css
โ”‚
โ”œโ”€โ”€ views
โ”‚   โ”œโ”€โ”€ signup.ejs
โ”‚   โ”œโ”€โ”€ login.ejs
โ”‚   โ””โ”€โ”€ dashboard.ejs
โ”‚
โ”œโ”€โ”€ app.js
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ package-lock.json
โ””โ”€โ”€ .gitignore

๐Ÿ”„ Authentication Flow

1. User Registration

User signs up with username & password Password is hashed using bcrypt Stored securely in MongoDB

2. User Login

Credentials are verified Password compared using bcrypt JWT token generated on success

3. JWT Authentication

Token stored in browser cookies Used to access protected routes

4. Protected Dashboard

Only authenticated users can access dashboard Invalid token blocks access

5. Logout

JWT cookie is cleared User redirected to login page


๐ŸŽฅ Project Flow

Signup โ†’ Login โ†’ Dashboard โ†’ Logout


๐Ÿ“š Concepts Learned

Express Routing

MongoDB & Mongoose

Schema & Models

Password Hashing

Authentication vs Authorization

JWT Tokens

Cookies & Sessions

Middleware

Protected Routes

EJS Templating

CRUD Operations


โš™๏ธ Installation

git clone https://github.com/LashminiAD/authentication-system-nodejs.git cd authentication-system-nodejs npm install Start MongoDB mongodb://localhost:27017/AuthDB Run Project npm start

or

nodemon app.js Open in Browser http://localhost:3000

๐Ÿ”ฎ Future Improvements

Forgot Password Feature

Email Verification

Session Expiry Handling

Remember Me Option

Role-Based Authentication

React Frontend Integration

Deployment on Render/Vercel


๐Ÿ‘ฉโ€๐Ÿ’ป Author

Lashmini A D โค๏ธ

About

Authentication System built with Node.js, Express.js, MongoDB, JWT, bcrypt, and Cookies. Features secure user registration, login authentication, password hashing, protected routes, session management, and logout functionality with clean minimal UI with EJS templating

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Packages

 
 
 

Contributors