Overview
Proyecto uses Django’s built-in authentication system (django.contrib.auth) to provide secure user authentication and session management. The system enforces strict security policies including short session timeouts and comprehensive password validation.
All views in Proyecto require authentication. Unauthenticated users are automatically redirected to the login page.
Session Management
Proyecto implements strict session security with the following configuration:Session Behavior
- Session Duration: Sessions automatically expire after 5 minutes of inactivity
- Browser Close: Sessions are terminated when you close your browser
- Security: This prevents unauthorized access if you leave your workstation unattended
Login System
Login Process
Proyecto uses Django’s authentication middleware to handle user login:Access the Login Page
Navigate to the login URL. If you try to access any protected page, you’ll be automatically redirected to login.
Enter Credentials
Provide your username and password. These are validated against Django’s User model.
Authentication
Django authenticates your credentials using the AuthenticationMiddleware (settings.py:48).
Protected Views
All views in Proyecto are protected with the@login_required decorator:
@login_required decorator ensures that:
- Only authenticated users can access the view
- Unauthenticated requests are redirected to the login page
- The current user is available via
request.user
Creating Superusers
Superusers have full administrative access to the system. You can create them using the custom user creation interface:Password Validation
Proyecto enforces strict password requirements using Django’s built-in validators:Password Requirements
UserAttributeSimilarityValidator
UserAttributeSimilarityValidator
Prevents passwords that are too similar to user attributes like username or email. This stops users from creating easily guessable passwords.
MinimumLengthValidator
MinimumLengthValidator
Enforces a minimum password length (default: 8 characters). Longer passwords are more resistant to brute-force attacks.
CommonPasswordValidator
CommonPasswordValidator
Rejects commonly used passwords (e.g., “password123”, “qwerty”). This validator checks against a list of thousands of common passwords.
NumericPasswordValidator
NumericPasswordValidator
Prevents entirely numeric passwords (e.g., “12345678”). Passwords must contain a mix of character types.
Security Middleware
Proyecto implements Django’s security middleware stack:Security Features
- SecurityMiddleware: Provides various security enhancements like SSL/HTTPS redirects
- CsrfViewMiddleware: Protects against Cross-Site Request Forgery attacks
- AuthenticationMiddleware: Associates users with requests based on sessions
- XFrameOptionsMiddleware: Prevents clickjacking attacks by controlling iframe embedding
Security Best Practices
Production Recommendations
-
Environment Variables: Store sensitive settings in environment variables
-
Debug Mode: Set
DEBUG = Falsein production (currently True in settings.py:25) -
ALLOWED_HOSTS: Update the allowed hosts list for your production domain
- HTTPS: Always use HTTPS in production and enable security headers
-
Session Security: Consider adjusting
SESSION_COOKIE_AGEbased on your use case- Current: 300 seconds (5 minutes) - very strict
- Consider: 1800 seconds (30 minutes) for better usability
Logout
When you log out, you’re automatically redirected to the home page (LOGOUT_REDIRECT_URL = '/'). Since the home page requires authentication, you’ll immediately see the login form.
Logout Behavior
- All session data is cleared
- Authentication cookies are invalidated
- You’re redirected to the logout URL, which then redirects to login
- Any in-progress work not saved to the database is lost
Always save your work before logging out or letting your session expire to prevent data loss.