Reusable Flask authentication module with registration, login, and email verification
Project description
Flask Accounts
Plug-and-play authentication for Flask with UI, database, and email verification included.
A modular, reusable authentication system for Flask applications.
✨ Features
- User registration
- Login / logout
- Email verification (with expiration + resend)
- Password hashing (Werkzeug)
- PostgreSQL backend
- Session-based authentication
- Configurable UI (banners, redirects, custom CSS)
- SMTP email support (or terminal mode for development)
🚀 Installation
pip install flask-accounts
⚡ Quick Start
from flask import Flask
from flask_accounts import init_auth
app = Flask(__name__)
app.config["SECRET_KEY"] = "your-secret-key"
# Database
app.config["DB_HOST"] = "localhost"
app.config["DB_NAME"] = "accountdb"
app.config["DB_USER"] = "accountuser"
app.config["DB_PASSWORD"] = "yourpassword"
# Email
app.config["SMTP_HOST"] = "smtp.gmail.com"
app.config["SMTP_PORT"] = 587
app.config["SMTP_USERNAME"] = "youremail@gmail.com"
app.config["SMTP_PASSWORD"] = "your_app_password"
app.config["SMTP_FROM_EMAIL"] = "youremail@gmail.com"
# Dev mode
app.config["USE_TERMINAL_EMAIL"] = True
init_auth(app)
if __name__ == "__main__":
app.run(debug=True)
Then visit: http://localhost:5000/auth/register
📸 Screenshots
🔐 Login
📝 Register
📧 Email Verification
⚙️ Configuration
Required
SECRET_KEY
DB_HOST
DB_NAME
DB_USER
DB_PASSWORD
SMTP_HOST
SMTP_PORT
SMTP_USERNAME
SMTP_PASSWORD
SMTP_FROM_EMAIL
USE_TERMINAL_EMAIL
Optional
LOGIN_REDIRECT = "home"
REGISTER_REDIRECT = "verify_email"
VERIFY_EMAIL_REDIRECT = "login"
LOGIN_BANNER = "Welcome Back"
LOGIN_BANNER_MSG = "Login to your account"
REGISTER_BANNER = "Create Account"
REGISTER_BANNER_MSG = "Register to get started"
AUTH_CUSTOM_CSS = "custom.css"
🎨 Custom Styling
Place CSS in your app:
your_app/static/custom.css
Then:
AUTH_CUSTOM_CSS = "custom.css"
🗄️ Database Setup
CREATE DATABASE accountdb;
CREATE USER accountuser WITH PASSWORD 'yourpassword'; GRANT ALL PRIVILEGES ON DATABASE accountdb TO accountuser;
Run schema:
psql -U accountuser -d accountdb -f schema.sql
🔐 Authentication Flow
- Register
- Verify email
- Login
- Access app
🔌 Routes
/auth/register
/auth/login
/auth/logout
/auth/verify-email
/auth/resend-code
🧠 Protected Route Example
from flask import session, redirect, url_for
@app.route("/dashboard")
def dashboard():
if "user_id" not in session:
return redirect(url_for("auth.show_login"))
return "Welcome to your dashboard"
⚠️ Notes
- Session-based auth
- PostgreSQL via psycopg2
🚀 Roadmap
- Password reset
- OAuth
- JWT
- SQLAlchemy
🧑💻 Author
Gabriel Leffew
📜 License
MIT
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flask_accounts-0.1.3.tar.gz.
File metadata
- Download URL: flask_accounts-0.1.3.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bdcf6c786e104b076df6cdaa80ce8f6a3726549df9e456d04fb4a7739f8731b7
|
|
| MD5 |
68ba2c5877d9e3f698236a801db2bae1
|
|
| BLAKE2b-256 |
c50c3c4922240098963e2beacdf10ba62e6b19740b284ca8f7ede8fc55f06d06
|
File details
Details for the file flask_accounts-0.1.3-py3-none-any.whl.
File metadata
- Download URL: flask_accounts-0.1.3-py3-none-any.whl
- Upload date:
- Size: 12.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1f46fd833d814d6e6a3f45cdade7ba2cbf6af9e5598246f18806d66c702227e9
|
|
| MD5 |
4249989fb6a0d89e92494f0b26f0c527
|
|
| BLAKE2b-256 |
7046c821e50ba18e9cb72a2b0721544c3a33b9b86fa9a3254a6aa121087248ef
|