π Flask Login System with SQLite
A beginner-friendly login & signup system using Flask and SQLite.
This project demonstrates:
- β User Signup (create a new account)
- β User Login (check credentials)
- β Session Management (keep users logged in)
- β Cookies (store "last visit" info)
- β "Remember Me" option (stay logged in even after closing browser)
π Project Structure
/project-folder
βββ app.py # Main Flask application
βββ users.db # SQLite database (auto-created)
βββ templates/
β βββ home.html # Home page (only for logged-in users)
β βββ login.html # Login form
β βββ signup.html # Signup form
β‘ Installation & Setup
1οΈβ£ Clone or Download
git clone https://github.com/yourusername/flask-login-system.git
cd flask-login-system
2οΈβ£ Create Virtual Environment (recommended)
python -m venv venv
source venv/bin/activate # On Mac/Linux
venv\Scripts\activate # On Windows
3οΈβ£ Install Dependencies
pip install flask
4οΈβ£ Run the App
python app.py
Flask will start at: π http://127.0.0.1:5000/
π₯οΈ Usage
Open
http://127.0.0.1:5000/signup- Create a new account.
Go to
http://127.0.0.1:5000/login- Enter username & password.
- Tick Remember Me if you want to stay logged in after closing browser.
After login β youβll be redirected to Home Page.
- It will also show your last visit info stored in cookies.
To logout β go to
http://127.0.0.1:5000/logout.
πͺ How It Works
Sessions
- Store who is logged in (
session["username"]). - By default, session ends when browser is closed.
- If "Remember Me" is checked β session lasts 7 days.
- Store who is logged in (
Cookies
- Store a
last_visitmessage. - If "Remember Me" is checked β cookie also lasts 7 days.
- Otherwise, cookie disappears when browser closes.
- Store a
β οΈ Security Notes (for teaching only!)
- Passwords are stored in plain text in this demo (β not secure).
- In real applications β always hash passwords using libraries like
werkzeug.securityorbcrypt.
β¨ Future Improvements
- Add password hashing for security
- Add email verification / password reset
- Use Flask-Login for better authentication management
π¨βπ» Author
Created as a teaching project for extreme beginners learning Flask, Sessions, and Cookies.