Skip to content

mohanevs/fastapi-auth-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FastAPI Authentication System

🚀 Introduction

This repository contains a basic user authentication system built using FastAPI as the backend framework and HTML + CSS for the frontend. The project demonstrates how to implement essential authentication features such as Login, User Registration, and Forgot Password while connecting FastAPI to a PostgreSQL database using the psycopg driver.

This project is intended for learning purposes, beginners exploring FastAPI, and anyone who wants a clean reference implementation of a form-based authentication flow.


🛠️ Tech Stack Used

  • Backend: FastAPI (Python)
  • Frontend: HTML, CSS (Jinja2 Templates)
  • Database: PostgreSQL
  • Database Driver: psycopg
  • Templating Engine: Jinja2
  • Server: Uvicorn

✨ Features

  • User Login with credential validation
  • User Registration with PostgreSQL storage
  • Forgot Password functionality
  • Clean UI with static assets
  • FastAPI form handling using Form(...)
  • Modular and beginner-friendly project structure

📂 Project Structure

fastapi-auth-system/
│
├── main.py
├── requirements.txt
├── static/
│   ├── index.css
│   ├── register.css
│   ├── forgot.css
│   └── favicon.ico
│
├── templates/
│   ├── index.html
│   ├── register.html
│   └── forgot.html
│
├── designs/
│   └── background images
│
├── env/   (ignored in git)
└── README.md

📥 How to Use This Project

Follow the steps below to run this project locally on your system.

1️⃣ Clone the Repository

git clone https://github.com/mohanevs/fastapi-auth-system.git
cd fastapi-auth-system

2️⃣ Create and Activate Virtual Environment

python -m venv env

Activate (Windows):

env\Scripts\activate

Activate (Linux / macOS):

source env/bin/activate

3️⃣ Install Required Dependencies

pip install -r requirements.txt

4️⃣ PostgreSQL Database Setup

Make sure PostgreSQL is running and create a database named:

login_db

Create a users table (example schema):

CREATE TABLE users (
    id SERIAL PRIMARY KEY,
    fname VARCHAR(50),
    lname VARCHAR(50),
    phone BIGINT,
    email VARCHAR(100),
    place VARCHAR(100),
    username VARCHAR(50) UNIQUE,
    password VARCHAR(100)
);

Update database credentials inside main.py if required.


5️⃣ Run the FastAPI Server

uvicorn main:app --reload

6️⃣ Open in Browser


📌 Notes

  • Passwords are currently stored in plain text (for learning purposes only).
  • In future versions, password hashing and authentication tokens will be added.

🌐 Live Deployment

This project is deployed on Render and can be accessed using the link below:

🔗 Live Demo:
https://fastapi-auth-system-357d.onrender.com

You can test the following routes directly in the browser:

  • / → Login page
  • /register → User registration
  • /forgot → Forgot password
  • /view → View registered users (JSON response)

Note: The application uses a Render-hosted PostgreSQL database and environment variables for secure configuration.


Crafted with ❤️ by Vaibhavsingh Mohane


⭐ If you found this project helpful, consider giving it a star!

About

Basic authentication system using FastAPI, PostgreSQL, and form-based HTML frontend.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors