Login Process
Endpoint:login_process.php
Method: POST
Description: Authenticates users based on their ID format. Student IDs are numeric, while teacher IDs start with ‘T’ followed by 4 digits.
Request Parameters
User identifier. Can be:
- Numeric student ID (e.g.,
12345) - Teacher ID starting with T (e.g.,
T1234)
User’s password (minimum 8 characters)
Authentication Flow
-
Student Authentication (numeric ID):
- Queries
studentstable usingstudent_id - Verifies password using
password_verify() - Sets session variables:
user_id,user_type,student_id - Redirects to
student_dashboard.php
- Queries
-
Teacher Authentication (ID starts with ‘T’):
- Queries
teacherstable usingteacher_id - Verifies password using
password_verify() - Sets session variables:
user_id,user_type,teacher_id,teacher_name - Redirects to
teacher_dashboard.php
- Queries
Response Handling
Success:- Redirects to appropriate dashboard
- Session variables set for authenticated user
- Sets
$_SESSION['error']with descriptive message - Redirects back to
index.php - Error messages:
- “Invalid student ID or password. Please check your credentials and try again.”
- “Invalid teacher ID or password. Please check your credentials and try again.”
All passwords are hashed using PHP’s
PASSWORD_DEFAULT algorithm (bcrypt) for security.Registration
Endpoint:register.php
Method: POST
Description: Handles user registration for both students and teachers with different validation rules.
Student Registration
Must be set to
studentUnique student identifier (numeric)
Student’s full name
Valid email address
Password (minimum 8 characters)
Must match the password field
Teacher Registration
Must be set to
teacherTeacher ID in format
T\d{4} (e.g., T1234)Teacher’s full name
Valid email address
Password (minimum 8 characters)
Must match the password field
Validation Rules
Student ID:- Must be unique in the
studentstable - Can be any numeric format
- Must match pattern:
^T\d{4}$ - Must be unique in the
teacherstable - Examples: T1234, T5678, T0001
- Minimum 8 characters
- Must match confirmation password
- Automatically hashed using
password_hash($password, PASSWORD_DEFAULT)
Response Messages
Success (Student):- Generates QR code containing the student ID
- QR code displayed on page for immediate download
- “Passwords do not match”
- “Student ID already exists”
- “Teacher ID already exists”
- “Teacher ID must be in format T followed by 4 digits (e.g., T1234)”
- “Registration failed: [database error]“
Database Operations
Logout
Endpoint:logout.php
Method: GET
Description: Destroys the current session and redirects to the login page.
Process Flow
- Starts session with
session_start() - Destroys all session data with
session_destroy() - Redirects to
index.php
No parameters required. This endpoint simply terminates the active session.
Password Reset Flow
Step 1: Request Password Reset
Endpoint:reset_password.php
Method: POST
Description: Initiates password reset by validating user ID and email.
User’s ID (student ID or teacher ID)
Email address registered to the account
Process Flow
-
User Type Detection:
- Numeric ID → Student
- ID starting with ‘T’ → Teacher
-
Validation:
- Queries appropriate table (
studentsorteachers) - Matches both
userIDANDemail
- Queries appropriate table (
-
Token Generation:
- Generates secure random token:
bin2hex(random_bytes(32)) - Sets expiry: 1 hour from current time
- Stores in database with expiry timestamp
- Generates secure random token:
-
Session Setup:
-
Redirect: To
password_reset_form.php
Database Updates
- “Invalid user ID format.”
- “No account found with that ID and email combination.”
- “Invalid request.”
Step 2: Set New Password
Endpoint:update_password.php
Method: POST
Description: Updates password after token validation.
Reset token from session
User’s ID from session
Either ‘student’ or ‘teacher’
New password (minimum 8 characters)
Must match new_password
Validation Steps
- Password Match: Verify
new_password === confirm_password - Password Length: Minimum 8 characters
- Token Validation: Check token exists and not expired
Success Response
- Hash new password:
password_hash($newPassword, PASSWORD_DEFAULT) - Update database:
- Clear reset session variables
- Set success message: “Your password has been updated successfully. You can now login with your new password.”
- Redirect to
index.php
Error Messages
- “Passwords do not match.”
- “Password must be at least 8 characters long.”
- “Invalid or expired password reset token.”
- “Invalid request.”
Session Management
Session Variables
Student Session:Protected Pages
All dashboard pages check for valid session:Session data is automatically initiated in
config.php which should be included at the top of every protected page.