Assignments On Class 40
Real-World Project - Part 2 (Concept)
Assignment 1: Implementing Final Features
Objective: Ensure that all core features of your project are implemented and fully functional.
Task:
1. Create a feature checklist for your project. Include the following functionalities:
o User authentication (login, registration).
o CRUD operations for a key entity (e.g., products for an e-commerce website).
o Admin functionality (if applicable).
o Any additional features that your project requires (e.g., search, filter, cart).
Step-by-Step Solution:
1. User Authentication:
o Ensure that the login and registration forms are working correctly.
o Use password_hash() to store hashed passwords securely.
o Use password_verify() to authenticate users on login.
o Example:
// Registration
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
// Store $hashedPassword in the database
// Login
if (password_verify($password, $storedHashedPassword)) {
// Successful login
}
2. CRUD Operations:
o Create, Read, Update, and Delete functionality for your main entity.
o Example for a product in an e-commerce project:
§ Create: Add new products to the database.
§ Read: Display products on the homepage.
§ Update: Allow admin to edit product details.
§ Delete: Allow admin to delete products.
§ Example:
// Create
$query = "INSERT INTO products (name, price) VALUES (?, ?)";
$stmt = $conn->prepare($query);
$stmt->execute([$name, $price]);
3. Admin Panel (if applicable):
o Implement admin-only features, such as managing users or reviewing orders.
o Example: Add a check to ensure that only admins can access certain pages.
if ($_SESSION['role'] != 'admin') {
header('Location: index.php');
exit();
}
Deliverable: Provide the implementation of the features along with a demo of each working correctly.
Assignment 2: UI/UX Improvements
Objective: Enhance the UI/UX of your project to ensure it is user-friendly and responsive.
Task:
1. Evaluate your current UI and identify areas for improvement.
2. Apply at least three improvements such as:
o Improving navigation.
o Making the website mobile-friendly.
o Using consistent design elements (colors, fonts).
o Improving the layout of important pages (e.g., product page, order confirmation).
Step-by-Step Solution:
1. Improving Navigation:
o Add a sticky navigation bar for easy access to important links.
o Use a simple and intuitive menu structure.
Example:
<nav class="navbar fixed-top">
<ul>
<li><a href="home.php">Home</a></li>
<li><a href="products.php">Products</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
</nav>
2. Mobile-Friendly Design (Responsive):
o Use media queries to ensure the layout adjusts for different screen sizes.
o Example:
@media (max-width: 768px) {
.navbar ul {
display: block;
text-align: center;
}
}
3. Consistent Design Elements:
o Ensure that buttons, links, and fonts are consistent across the website. Use the same color scheme, font family, and button style throughout.
o Example:
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
.btn {
background-color: #007bff;
color: white;
}
Deliverable: Show the updated UI with a screenshot or a demo link, demonstrating the improvements.
Assignment 3: Database Optimization
Objective: Optimize the database structure and queries to ensure better performance and scalability.
Task:
1. Review the database schema of your project and identify areas for normalization (if necessary).
2. Optimize at least one SQL query to improve performance.
3. Add indexes to frequently queried columns.
Step-by-Step Solution:
1. Reviewing Database Schema:
o Check that all tables are normalized to at least the third normal form (3NF).
o Ensure that redundant data is minimized and relationships are properly defined using foreign keys.
o Example:
CREATE TABLE products (
id INT PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(100),
price DECIMAL(10, 2)
);
CREATE TABLE orders (
id INT PRIMARY KEY AUTO_INCREMENT,
product_id INT,
FOREIGN KEY (product_id) REFERENCES products(id)
);
2. Optimizing SQL Queries:
o Use indexes on frequently queried columns to speed up SELECT queries.
o Example:
CREATE INDEX idx_product_name ON products(name);
3. Adding Indexes:
o Identify columns that are frequently used in WHERE, ORDER BY, and JOIN clauses.
o Example:
CREATE INDEX idx_orders_product_id ON orders(product_id);
Deliverable: Provide the optimized database schema and a description of how performance was improved.
Assignment 4: Security Implementation
Objective: Ensure your project follows best security practices to protect user data.
Task:
1. Implement the following security measures:
o Use password_hash() and password_verify() for secure password storage and verification.
o Prevent SQL injection by using prepared statements.
o Implement XSS protection by sanitizing user input.
o Ensure secure session management by regenerating session IDs.
Step-by-Step Solution:
1. Password Hashing:
o When a user registers, hash the password before storing it.
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);
o When logging in, verify the password using password_verify().
if (password_verify($password, $storedHashedPassword)) {
// Login successful
}
2. Prevent SQL Injection:
o Use prepared statements to prevent SQL injection.
$stmt = $conn->prepare("SELECT * FROM users WHERE email = ?");
$stmt->bind_param("s", $email);
$stmt->execute();
3. XSS Protection:
o Use htmlspecialchars() to sanitize user input.
$name = htmlspecialchars($_POST['name']);
4. Session Management:
o Regenerate session IDs after login to prevent session fixation attacks.
session_regenerate_id(true);
Deliverable: Provide a document explaining how these security measures were implemented with examples.
Assignment 5: Testing and Debugging
Objective: Test the project thoroughly to identify and fix bugs before deployment.
Task:
1. Create a set of test cases to test key features of your project (login, registration, CRUD operations).
2. Identify at least three bugs in your project and document how they were fixed.
3. Run edge cases to ensure that the system behaves correctly under unusual circumstances (e.g., invalid inputs, empty fields).
Step-by-Step Solution:
1. Create Test Cases:
o Write test cases to check the validity of forms, correct CRUD functionality, and admin features.
§ Test Case 1: User registration with valid and invalid email formats.
§ Test Case 2: Creating a product with missing fields (e.g., empty name or price).
§ Test Case 3: Admin login with correct and incorrect credentials.
2. Identify and Fix Bugs:
o Debug the project by inspecting logs and checking for issues.
§ Bug 1: Login fails because password hashing wasn't used properly.
§ Fix: Implement password_hash() for registration and password_verify() for login.
3. Edge Case Testing:
o Test with incorrect inputs like entering a very long product name, leaving fields blank, or entering invalid email formats.
o Example:
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) {
echo "Invalid email!";
}
Deliverable: Submit the test cases, a list of bugs found, and how they were fixed.