Skip to content

abreuclariana/Authentication-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Authentication System with Express, MongoDB, and Bcrypt

A modern, secure user authentication system built with Node.js, Express, MongoDB Atlas, and Bcrypt for secure password hashing. Features a beautiful, responsive UI and allows users to register, log in, and share secrets anonymously.

🌐 Live Demo

πŸš€ Production URL: https://register-authentication-2.onrender.com

πŸš€ Technologies Used

  • Node.js - JavaScript runtime environment for backend development
  • Express - Web framework for creating the server
  • MongoDB Atlas - Cloud NoSQL database to store user data
  • Mongoose - ODM library for MongoDB data modeling
  • Bcrypt - Library for secure password hashing
  • EJS - Template engine for rendering dynamic pages
  • Express-Session - Session management for user authentication
  • Dotenv - Environment variable management
  • Bootstrap - Frontend framework for responsive design
  • FontAwesome - Icons library

πŸ“‚ Project Structure

πŸ“¦ register-authentication
β”œβ”€β”€ πŸ“‚ views/                 # EJS templates
β”‚   β”œβ”€β”€ πŸ“‚ partials/          # Header and footer components
β”‚   β”œβ”€β”€ πŸ“„ home.ejs          # Landing page
β”‚   β”œβ”€β”€ πŸ“„ login.ejs         # Login page
β”‚   β”œβ”€β”€ πŸ“„ register.ejs      # Registration page
β”‚   β”œβ”€β”€ πŸ“„ secrets.ejs       # Protected secrets page
β”‚   └── πŸ“„ submit.ejs        # Submit secrets page
β”œβ”€β”€ πŸ“‚ public/               # Static files
β”‚   └── πŸ“‚ css/
β”‚       └── πŸ“„ styles.css    # Custom styles
β”œβ”€β”€ πŸ“œ app.js               # Main server code
β”œβ”€β”€ πŸ“œ package.json         # Project dependencies
β”œβ”€β”€ πŸ“œ .env                 # Environment variables (not tracked)
β”œβ”€β”€ πŸ“œ .gitignore          # Git ignore rules
└── πŸ“œ README.md           # Project documentation

πŸ”§ Setup and Installation

1️⃣ Clone the repository:

git clone https://github.com/abreuclariana/register-authentication
cd register-authentication

2️⃣ Install dependencies:

npm install

3️⃣ Configure environment variables:

Create a .env file in the root directory:

# Database Configuration
MONGODB_URI=mongodb://localhost:27017/userDB

# Session Configuration
SESSION_SECRET=your-super-secret-session-key-change-this-in-production

# Server Configuration
PORT=4000
NODE_ENV=development

4️⃣ Start MongoDB locally:

# Create data directory
mkdir C:\data\db

# Start MongoDB
mongod --dbpath C:\data\db

5️⃣ Run the server:

npm start
# or
node app.js

The server will be running at http://localhost:4000 πŸš€

🌐 Production Deployment

MongoDB Atlas Setup:

  1. Create MongoDB Atlas account: https://cloud.mongodb.com/
  2. Create cluster: Choose M0 Sandbox (free tier)
  3. Configure database access: Create user with password
  4. Configure network access: Allow access from anywhere (0.0.0.0/0)
  5. Get connection string: Copy the MongoDB Atlas connection string

Render Deployment:

  1. Connect GitHub repository to Render
  2. Add environment variables:
    MONGODB_URI=mongodb+srv://username:password@cluster0.xxxxx.mongodb.net/userDB?retryWrites=true&w=majority
    SESSION_SECRET=your-production-secret-key
    NODE_ENV=production
    
  3. Deploy: Render will automatically build and deploy

πŸ›  Features

βœ… Authentication Features:

  • User Registration with email validation
  • Secure Login with password verification
  • Session Management with express-session
  • Password Hashing with bcrypt (10 salt rounds)
  • Protected Routes with authentication middleware

βœ… User Interface:

  • Responsive Design with Bootstrap
  • Modern UI with gradients and animations
  • Error Handling with user-friendly messages
  • Success Notifications for user actions
  • Mobile-First approach

βœ… Database Features:

  • MongoDB Atlas cloud database
  • User Collection for storing credentials
  • Secrets Collection for anonymous secrets
  • Data Validation with Mongoose schemas

βœ… Security Features:

  • Password Hashing with bcrypt
  • Session Security with secret keys
  • Environment Variables for sensitive data
  • Input Validation and sanitization

πŸ“Œ Project Routes

Method Route Description Authentication
GET / Home page with register/login ❌ Public
GET /login Login page ❌ Public
GET /register Registration page ❌ Public
POST /register User registration ❌ Public
POST /login User authentication ❌ Public
GET /secrets Protected secrets page βœ… Required
GET /submit Submit secrets page βœ… Required
POST /submit Submit new secret βœ… Required
POST /logout User logout βœ… Required

🎨 UI/UX Features

Design Elements:

  • Glass Morphism effects on home page
  • Gradient Backgrounds for modern look
  • Floating Animations for interactive elements
  • Responsive Cards with shadows and borders
  • Icon Integration with FontAwesome
  • Color-coded buttons and alerts

User Experience:

  • Intuitive Navigation between pages
  • Clear Error Messages in Portuguese/English
  • Success Feedback for user actions
  • Loading States and transitions
  • Mobile Optimization for all devices

πŸ”’ Security Considerations

  • Environment Variables: Sensitive data stored in .env
  • Password Hashing: Bcrypt with 10 salt rounds
  • Session Management: Secure session configuration
  • Input Validation: Server-side validation
  • HTTPS: Production deployment with SSL
  • Database Security: MongoDB Atlas with authentication

πŸš€ Performance Features

  • Efficient Database Queries with Mongoose
  • Session Optimization with proper configuration
  • Static File Serving with Express
  • Error Handling with proper HTTP status codes
  • Responsive Design for all screen sizes

πŸ“± Browser Support

  • Chrome 90+
  • Firefox 88+
  • Safari 14+
  • Edge 90+

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ‘¨β€πŸ’» Developer

Developed with ❀️ by Clariana Abreu


πŸ“ž Support

If you have any questions or need help with the project, feel free to:


πŸŽ‰ This README.md provides comprehensive documentation for the authentication system, including setup instructions, deployment guide, and feature overview!

Releases

No releases published

Packages

 
 
 

Contributors