GithubHelp home page GithubHelp logo

secure-auth-system's Introduction

Secure Auth System

A secure user authentication system built with Node.js, Express, and MongoDB.

Features

  • User Registration: Users can create an account by providing necessary information (username, email, password). The system securely stores user data in a MongoDB database and hashes passwords using bcrypt.
  • User Login: Users can log in using their credentials (username/email and password). Upon successful login, the backend generates a JSON Web Token (JWT) containing relevant user information.
  • Protected Routes: Logged-in users can access protected routes. A session is maintained using JWT.
  • Data Validation: Proper data validation is implemented on the server-side to ensure data integrity.
  • Security: User input is sanitized to prevent vulnerabilities like Cross-Site Scripting (XSS).

Endpoints

User Registration

  • URL: /api/auth/register
  • Method: POST
  • Body:
    {
      "username": "yourusername",
      "email": "[email protected]",
      "password": "yourpassword"
    }
  • Response:
    • 201 Created: User registered successfully.
    • 400 Bad Request: Validation error (e.g., username already exists, missing fields).

User Login

  • URL: /api/auth/login
  • Method: POST
  • Body:
    {
      "email": "[email protected]",
      "password": "yourpassword"
    }
  • Response:
    • 200 OK: Login successful, returns a JWT token.
    • 400 Bad Request: Validation error (e.g., incorrect password, missing fields).
    • 404 Not Found: User not found.

Protected Route

  • URL: /api/auth/protected-route
  • Method: GET
  • Headers:
    • x-auth-token: JWT token
  • Response:
    • 200 OK: Access granted.
    • 401 Unauthorized: Access denied, token missing or invalid.

Project Setup

  1. Clone the repository:

    git clone https://github.com/your-username/your-repository.git
  2. Navigate into the project directory:

    cd your-repository
  3. Install dependencies:

    npm install
  4. Set up environment variables:

    Create a .env file in the root directory and add the following:

    PORT=5000
    MONGO_URI=your_mongodb_connection_string
    JWT_SECRET=your_jwt_secret
    
  5. Start the server:

    nodemon app.js

Technologies Used

  • Node.js
  • Express
  • MongoDB
  • Mongoose
  • bcrypt
  • JWT
  • Express-validator

Security

  • XSS Protection: Implemented using express-validator to sanitize user inputs and prevent Cross-Site Scripting (XSS) attacks.

Contributing

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

Contact

E-mail - [email protected]

secure-auth-system's People

Contributors

tanmay0922 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.