A full-featured, production-ready authentication system built with Django 5 and Bootstrap 5. This project implements a complete user authentication flow using a custom User model, class-based views, and Django's built-in security framework — demonstrating clean architecture, reusable components, and industry best practices.
| Feature | Description |
|---|---|
| Custom User Model | Extends AbstractBaseUser + PermissionsMixin with a dedicated UserManager for full control over user creation |
| User Registration | Sign-up with username, email, and password — includes duplicate-checking validation |
| Login / Logout | Session-based authentication using Django's authenticate() and login() |
| Change Password | Authenticated users can update their password with current-password verification |
| Password Reset via Email | Forgot-password flow using Django's PasswordResetView with SMTP email delivery |
| Access Control Mixins | Custom LogoutRequiredMixin prevents authenticated users from accessing login/register pages |
| Responsive UI | Bootstrap 5 RTL-ready templates with clean, mobile-friendly layouts |
| Admin Panel | Custom User model registered in Django Admin for easy management |
- Backend: Python · Django 5.0
- Frontend: Django Templates · Bootstrap 5.3 (RTL)
- Database: SQLite (default, easily swappable)
- Authentication: Django's built-in auth framework with custom extensions
- Email: SMTP (Gmail) for password-reset emails
AUTHENTICATION/
└── authentication/ # Django project root
├── manage.py
├── db.sqlite3
├── authentication/ # Project configuration
│ ├── settings.py # Django settings, AUTH_USER_MODEL config
│ ├── urls.py # Root URL routing
│ ├── wsgi.py
│ └── asgi.py
└── account/ # Core authentication app
├── models.py # Custom User model (AbstractBaseUser)
├── managers.py # Custom UserManager (create_user / create_superuser)
├── views.py # CBVs: Login, Logout, Registration, ChangePassword, Home
├── forms.py # LoginForm, UserRegistrationForm, ChangePasswordForm
├── urls.py # App-level URL patterns + password reset routes
├── mixins.py # LogoutRequiredMixin
├── admin.py # User model admin registration
├── templates/
│ ├── base.html # Base layout (Bootstrap 5)
│ └── account/
│ ├── home.html
│ ├── login.html
│ ├── registration.html
│ └── change_password.html
└── static/
└── css/
└── main.css
Instead of relying on Django's default User, this project defines a custom model extending AbstractBaseUser and PermissionsMixin. This provides:
- Full control over authentication fields (
usernameas the login identifier,emailas required) - A custom
UserManagerwith explicitcreate_user()andcreate_superuser()methods - Proper email normalization and field validation
All views are implemented as class-based views for better code organization and reusability:
generic.Viewfor login (custom GET/POST handling)generic.CreateViewfor registrationgeneric.FormViewfor password changegeneric.TemplateViewfor the home page
LoginRequiredMixin— Protects authenticated-only pages (Home, Change Password)LogoutRequiredMixin(custom) — Redirects already-logged-in users away from Login and Registration pages
All forms include server-side validation:
- Duplicate username/email detection (case-insensitive)
- Password confirmation matching
- Current password verification for password changes
- Automatic Bootstrap
form-controlclass injection
- Python 3.10+
- pip
# Clone the repository
git clone https://github.com/ays19/AUTHENTICATION.git
cd AUTHENTICATION/authentication
# Create and activate a virtual environment
python -m venv venv
source venv/bin/activate # Linux/macOS
# venv\Scripts\activate # Windows
# Install dependencies
pip install django
# Apply migrations
python manage.py migrate
# Create a superuser (optional)
python manage.py createsuperuser
# Run the development server
python manage.py runserver| Page | URL |
|---|---|
| Home (protected) | http://127.0.0.1:8000/ |
| Login | http://127.0.0.1:8000/login/ |
| Registration | http://127.0.0.1:8000/registration/ |
| Change Password | http://127.0.0.1:8000/change_password/ |
| Password Reset | http://127.0.0.1:8000/password_reset/ |
| Admin Panel | http://127.0.0.1:8000/admin/ |
GET / → Home (requires login)
GET /login/ → Login page
POST /login/ → Authenticate user
GET /logout/ → Logout and redirect to login
GET /registration/ → Registration form
POST /registration/ → Create new user
GET /change_password/ → Change password form (requires login)
POST /change_password/ → Update password
GET /password_reset/ → Password reset request (email)
GET /reset/<uid>/<token>/ → Password reset confirmation
Custom User Model — account/models.py
class User(AbstractBaseUser, PermissionsMixin):
username = models.CharField(max_length=150, unique=True, validators=[UnicodeUsernameValidator])
email = models.EmailField(max_length=150, unique=True)
# ...
objects = UserManager()
USERNAME_FIELD = "username"
REQUIRED_FIELDS = ["email"]Custom UserManager — account/managers.py
class UserManager(BaseUserManager):
def create_user(self, username, email, password, **extra_fields):
email = self.normalize_email(email)
user = self.model(username=username, email=email, **extra_fields)
user.set_password(password)
user.save(using=self._db)
return userLogoutRequiredMixin — account/mixins.py
class LogoutRequiredMixin(object):
def dispatch(self, *args, **kwargs):
if self.request.user.is_authenticated:
return redirect('home')
return super().dispatch(*args, **kwargs)- Add JWT / Token-based authentication (Django REST Framework)
- Social login integration (Google, GitHub via
django-allauth) - User profile page with avatar upload
- Email verification on registration
- Rate limiting on login attempts
- Docker containerization
- Unit & integration test coverage
This project is open source and available for learning and reference purposes.
Built with ❤️ using Django 5 · Python 3