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.
- Backend: FastAPI (Python)
- Frontend: HTML, CSS (Jinja2 Templates)
- Database: PostgreSQL
- Database Driver: psycopg
- Templating Engine: Jinja2
- Server: Uvicorn
- 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
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
Follow the steps below to run this project locally on your system.
git clone https://github.com/mohanevs/fastapi-auth-system.git
cd fastapi-auth-systempython -m venv envActivate (Windows):
env\Scripts\activateActivate (Linux / macOS):
source env/bin/activatepip install -r requirements.txtMake sure PostgreSQL is running and create a database named:
login_dbCreate 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.
uvicorn main:app --reload- Login Page: http://127.0.0.1:8000/
- Register Page: http://127.0.0.1:8000/register
- Forgot Password: http://127.0.0.1:8000/forgot
- View Users (JSON): http://127.0.0.1:8000/view <-- view database
- Passwords are currently stored in plain text (for learning purposes only).
- In future versions, password hashing and authentication tokens will be added.
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!