The application includes a secure admin authentication system to protect administrative functions.
For Production Deployment:
-
ADMIN_PASSWORD_HASH - SHA256 hash of the admin password
# Generate the hash (replace 'your_secure_password' with actual password) echo -n "your_secure_password" | sha256sum # Set in production environment export ADMIN_PASSWORD_HASH=your_sha256_hash_here
-
SECRET_KEY - Flask session secret key (required)
# Generate a secure secret key python -c "import secrets; print(secrets.token_hex(32))" # Set in production environment export SECRET_KEY=your_generated_secret_key_here
For Development Only:
# Simple password authentication (NOT for production)
export ADMIN_PASSWORD=your_dev_password_here
export FLASK_ENV=developmentTo generate a password hash for production:
# Method 1: Using Python
python3 -c "import hashlib; print(hashlib.sha256('your_password_here'.encode()).hexdigest())"
# Method 2: Using command line
echo -n "your_password_here" | sha256sum | cut -d' ' -f1- Session-based Authentication: Admin sessions are managed securely
- Password Hashing: Production uses SHA256 hashing (never stores plain text)
- Environment Variables: No secrets stored in code
- Route Protection: Admin routes require authentication
- Session Timeout: Sessions expire when browser closes
- Access Logging: Failed login attempts are logged
/admin/login- Admin login page (public)/admin/logout- Admin logout (clears session)/admin/species- Species management (protected)/admin/species/<id>/edit- Edit species descriptions (protected)
- Never commit passwords or hashes to version control
- Use strong passwords (12+ characters, mixed case, numbers, symbols)
- Rotate admin passwords regularly
- Monitor admin access logs
- Use HTTPS in production
- Set secure environment variables in deployment platform
Render.com: (used here)
# Set environment variables in Render dashboard
ADMIN_PASSWORD_HASH=your_sha256_hash
SECRET_KEY=your_secret_key
FLASK_ENV=productionHeroku:
heroku config:set ADMIN_PASSWORD_HASH=your_sha256_hash
heroku config:set SECRET_KEY=your_secret_key
heroku config:set FLASK_ENV=productionIf admin credentials are compromised:
- Immediately change the admin password
- Generate new password hash
- Update environment variables
- Redeploy the application
- Review access logs for unauthorized activity
- Failed login attempts are logged with flash messages
- Successful logins redirect to admin interface
- All admin actions should be logged (future enhancement)
Important: This authentication system provides basic security for a research database. For production environments with sensitive data, consider implementing:
- Multi-factor authentication
- Role-based access control
- Database connection encryption
- Regular security audits
- Intrusion detection systems