@extends('layouts.app') @section('title', 'Tutorial') @section('content')
Step-by-step guide to set up and use the Laravel 2FA authentication system
git clone https://github.com/your-repo/laravel-2fa.git
cd laravel-2fa
composer install
npm install
cp .env.example .env
php artisan key:generate
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_2fa
DB_USERNAME=root
DB_PASSWORD=
Important Security Note
Generate secure random keys for 2FA encryption. You can use these commands:
# Generate encryption key (32 bytes)
openssl rand -base64 32
# Generate initialization vector (16 bytes)
openssl rand -base64 16
php artisan migrate
php artisan db:seed
Default Test User
Email: test@example.com
Password: password
php artisan serve
npm run dev
Navigate to the login page and enter your credentials. Use the test user: test@example.com / password
After successful login, you'll be redirected to the dashboard where you can manage your account
Click "Setup 2FA" to enable two-factor authentication. This will generate a QR code for your authenticator app
Use Google Authenticator, Authy, or any TOTP app to scan the QR code
Enter the 6-digit code from your authenticator app to confirm 2FA setup
Now when you log in, you'll need to enter a 2FA code to access protected areas
curl -X POST http://localhost:8000/api/auth/login \
-H "Content-Type: application/json" \
-d '{
"email": "test@example.com",
"password": "password"
}'
curl -X GET http://localhost:8000/api/auth/user \
-H "Authorization: Bearer {token}" \
-H "Accept: application/json"
curl -X POST http://localhost:8000/api/2fa/setup \
-H "Authorization: Bearer {token}" \
-H "Accept: application/json"
Ensure the endroid/qr-code package is installed and the GD extension is enabled in PHP.
Check that your device's time is synchronized. TOTP codes are time-sensitive.
Verify that your 2FA encryption keys are properly set in the .env file.
php artisan config:cache
php artisan route:clear
php artisan migrate:status
tail -f storage/logs/laravel.log
Modify the code to fit your specific requirements and branding
Deploy to production with proper security configurations
Read the full documentation for advanced features