Overview
NutriFit implements a robust authentication system powered by Laravel Fortify, providing secure user registration, login, password management, and two-factor authentication (2FA).All authentication features follow Laravel’s best security practices and include protection against common vulnerabilities.
Features
The authentication system includes:- User registration with email verification
- Secure login with rate limiting
- Password reset and recovery
- Two-factor authentication (2FA)
- Email validation with DNS/MX checking
- Data consent tracking
- Social authentication (Google OAuth)
Registration
User Registration Flow
New users register as patients by default (role_id: 3). The registration process includes:- Email and password validation
- Data consent agreement
- Email verification requirement
- Welcome email after verification
Email Validation
NutriFit uses theValidEmailDomain rule to verify that email addresses have valid DNS and MX records, preventing fake or disposable email addresses.
Email Verification
Email verification is required for all users before accessing protected features.Route Protection
Routes requiring verified email use theverified middleware:
routes/web.php
Two-Factor Authentication (2FA)
Enabling 2FA
Users can enable two-factor authentication from their settings page at/settings/two-factor.
2FA uses TOTP (Time-based One-Time Password) compatible with apps like Google Authenticator, Authy, and 1Password.
2FA Configuration
config/fortify.php
2FA Setup Process
Recovery Codes
When 2FA is enabled, users receive recovery codes that can be used if they lose access to their authenticator app.Password Management
Password Reset Flow
- User requests password reset
- System sends reset email using
ResetPasswordNotification - User clicks link and sets new password
- System sends confirmation email using
PasswordChangedNotification
Password Requirements
Passwords must meet Laravel’s default password rules:- Minimum 8 characters
- Must be confirmed (entered twice)
- Cannot be commonly used passwords
Forced Password Change
New patients created by administrators receive a default password and must change it on first login.routes/web.php
Social Authentication
Google OAuth
NutriFit supports Google OAuth for patient registration and login.routes/web.php
OAuth Flow
Rate Limiting
Login attempts are rate-limited to prevent brute force attacks:config/fortify.php
Notifications
The authentication system sends several email notifications:Welcome Email
Sent after email verification
Email Verification
Sent on registration
Password Reset
Sent when password reset requested
Password Changed
Sent after password change
Account Enabled
Sent when admin enables account
Account Disabled
Sent when admin disables account
Security Best Practices
Email Validation
Email Validation
All email addresses are validated against DNS/MX records to prevent fake emails.
Password Hashing
Password Hashing
Passwords are hashed using bcrypt with Laravel’s default cost factor.
CSRF Protection
CSRF Protection
All forms include CSRF token validation.
Rate Limiting
Rate Limiting
Login attempts are limited to prevent brute force attacks.
Session Management
Session Management
Secure session handling with httpOnly cookies.
Related Resources
User Roles
Learn about role-based access control
Notifications
Explore the notification system