Overview
Wecode uses Laravel’s built-in authentication system with custom LDAP integration. TheAuth::routes() call in web.php registers all standard authentication routes, which are then handled by controllers in app/Http/Controllers/Auth/.
Authentication Routes
Standard Routes
TheAuth::routes() method registers these routes:
| Method | URI | Name | Controller | Description |
|---|---|---|---|---|
| GET | /login | login | LoginController@showLoginForm | Display login form |
| POST | /login | - | LoginController@login | Process login |
| POST | /logout | logout | LoginController@logout | Logout user |
| GET | /register | register | RegisterController@showRegistrationForm | Display registration form |
| POST | /register | - | RegisterController@register | Process registration |
| GET | /password/reset | password.request | ForgotPasswordController@showLinkRequestForm | Password reset request form |
| POST | /password/email | password.email | ForgotPasswordController@sendResetLinkEmail | Send reset link email |
| GET | /password/reset/{token} | password.reset | ResetPasswordController@showResetForm | Password reset form |
| POST | /password/reset | password.update | ResetPasswordController@reset | Process password reset |
| GET | /password/confirm | password.confirm | ConfirmPasswordController@showConfirmForm | Password confirmation form |
| POST | /password/confirm | - | ConfirmPasswordController@confirm | Process password confirmation |
| GET | /email/verify | verification.notice | VerificationController@show | Email verification notice |
| GET | /email/verify/{id}/{hash} | verification.verify | VerificationController@verify | Verify email |
| POST | /email/resend | verification.resend | VerificationController@resend | Resend verification email |
Login System
LoginController
Location:app/Http/Controllers/Auth/LoginController.php
Constructor
guest- Only non-authenticated users can access login routes- Exception:
logoutmethod accessible to authenticated users
login()
User’s username
User’s password
Remember me checkbox (optional)
-
Via Remember Cookie
- Check if user has valid remember token
- Auto-login if token valid
-
LDAP Authentication (if enabled)
- Connect to AD/LDAP server
- Validate credentials
- Fetch user info (name, email)
- Login existing user or create new user
-
Database Authentication
- Check credentials against database
- Hash comparison for password
- Success: Redirect to intended page or
/home - Failure: Redirect back with errors
LDAP Integration
uit_ldap()
LDAP username
LDAP password
LDAP_OPT_PROTOCOL_VERSION: 3LDAP_OPT_REFERRALS: 0LDAP_OPT_TIMELIMIT: 1 secondLDAP_OPT_NETWORK_TIMEOUT: 1 second
ldap_authentication()
Username to authenticate
Password to verify
Whether to remember the user
- Call
uit_ldap()to validate credentials - Look up user in local database by username
- If found, log in user
- Optionally update display name from LDAP
- Optionally create new user if not exists (commented out)
logout()
- Call
Auth::logout()to clear authentication - Invalidate session
- Regenerate session token (CSRF protection)
POST /logout
Registration System
RegisterController
Location:app/Http/Controllers/Auth/RegisterController.php
Constructor
guest- Only non-authenticated users can register
validator()
Registration code (must match system setting)
Username (alpha-dash, max 50 chars, unique)
Display name (optional, max 255 chars)
Email address (valid email, max 255 chars, unique)
Password (min 8 chars, must be confirmed)
create()
- Check if registration is enabled
- Hash password
- Assign default student role
- Set trial time from settings
- Create user record
Password Reset System
ForgotPasswordController
Handles sending password reset links via email. Route:GET /password/reset
Process:
- User enters email address
- System sends reset link to email
- Link contains unique token
- Link expires after configured time
ResetPasswordController
Handles the actual password reset. Route:GET /password/reset/{token}
Process:
- User clicks link in email
- Token validated
- User enters new password
- Password updated and user logged in
Session Management
Session Lifecycle
-
Login
- Session created
- User ID stored in session
- Remember token generated (if requested)
-
Active Session
- Session data persisted across requests
- CSRF token in session
- User authenticated via session
-
Logout
- Session invalidated
- CSRF token regenerated
- Remember cookie deleted (if exists)
Remember Me Feature
When “Remember Me” is checked:- Creates persistent cookie (default 2 weeks)
- Cookie contains encrypted token
- User auto-logged on return visits
- Token stored in
remember_tokencolumn
Security Features
CSRF Protection
All POST routes require CSRF token:Password Hashing
Passwords hashed using bcrypt:Throttling
Laravel includes login throttling to prevent brute force:- Too many failed attempts = temporary lockout
- Configurable in AuthenticatesUsers trait
Trial Period System
Wecode includes a trial period system for new users: During Registration:- User registers with trial period (hours)
- User has full access during trial
- After trial expires, role automatically downgraded to guest
- Guest role has limited permissions
Login Tracking
Wecode tracks user login times:- Track user engagement
- Identify inactive accounts
- Calculate usage metrics
Middleware
guest
Protects routes that should only be accessible to non-authenticated users:- Login form
- Registration form
- Password reset request
auth
Protects routes that require authentication:- All application features
- User dashboard
- Submissions, assignments, etc.
Authentication Configuration
Guards
Wecode uses the defaultweb guard:
- Session-based authentication
- Stores user ID in session
- Uses database user provider
Providers
Users table as authentication provider:- Model:
App\Models\User - Table:
users - Password field:
password
Customization
Custom Login Logic
Wecode overrides default login() method:- Adds LDAP authentication
- Trial period checking
- Login time tracking
Custom Registration Logic
Wecode adds:- Registration code requirement
- Trial period assignment
- Role assignment
- Optional LDAP auto-creation
Related Settings
enable_registration
Type: Boolean Description: Enable/disable new user registration Effect: When false, registration form shows 403 errorregistration_code
Type: String (regex pattern) Description: Required code to register Usage: Limit registration to users with codedefault_trial_time
Type: Integer (hours) Description: Trial period duration for new users Effect: User downgraded to guest after expirationError Messages
Login Errors
Registration Errors
- Invalid registration code
- Username already taken
- Email already taken
- Password too short
- Password confirmation mismatch
Best Practices
For Users
- Use strong passwords (min 8 characters)
- Don’t share credentials
- Logout when done
- Use “Remember Me” only on personal devices
For Administrators
- Set strong registration codes
- Monitor trial period expiration
- Review login tracking data
- Configure LDAP if using institutional authentication
- Enable/disable registration as needed

