Security Features and Testing - Pine Valley Furniture Portal

Problem 1: Necessary Security Features

The following are essential security features implemented in our semester project:

#Security FeatureDescription
1AuthenticationRestricts access based on user login using username/password.
2AuthorizationControls access to different functionalities based on user roles (Admin, Customer).
3Input ValidationPrevents SQL injection and XSS by sanitizing all user inputs using Regex and server-side checks.
4Password HashingUser passwords are hashed using SHA256 before storing in the database.
5Session TimeoutAutomatically logs out users after 15 minutes of inactivity.
6HTTPS EnforcementEnsures encrypted communication via SSL/TLS (assumed enforced on deployment).
7SQL ParameterizationPrevents SQL injection by using parameterized queries in ADO.NET.

Problem 2: Code Implementation

Login (Authentication & Hashing)

string hashedPassword = ComputeSha256Hash(txtPassword.Text);
SqlCommand cmd = new SqlCommand("SELECT * FROM Users WHERE Username=@u AND PasswordHash=@p", conn);
cmd.Parameters.AddWithValue("@u", txtUsername.Text);
cmd.Parameters.AddWithValue("@p", hashedPassword);
                

Authorization Example

if (Session["Role"].ToString() != "Admin") {
    Response.Redirect("AccessDenied.aspx");
}
                

Input Validation

if (!Regex.IsMatch(txtEmail.Text, @"^[^@\s]+@[^@\s]+\.[^@\s]+$")) {
    lblError.Text = "Invalid email format.";
}
                

Session Timeout (Web.config)

<system.web>
  <sessionState timeout="15" />
</system.web>
                

SQL Parameterization

SqlCommand cmd = new SqlCommand("INSERT INTO Orders (CustomerId, ProductId) VALUES (@cid, @pid)", conn);
cmd.Parameters.AddWithValue("@cid", customerId);
cmd.Parameters.AddWithValue("@pid", productId);
                

Password Hashing Function (Utility)

public string ComputeSha256Hash(string rawData) {
    using (SHA256 sha256 = SHA256.Create()) {
        byte[] bytes = sha256.ComputeHash(Encoding.UTF8.GetBytes(rawData));
        return BitConverter.ToString(bytes).Replace("-", "").ToLower();
    }
}
                

Live Demo: Click here to view the demo

Problem 3: Test Cases & Reports

The following table outlines the test cases for security features:

FeatureTest CaseExpected Result
AuthenticationLogin with valid/invalid credentialsAccess granted or denied
AuthorizationTry to access admin page as customerAccess Denied
Input ValidationSubmit script tags in inputInput rejected
Password HashingVerify password in DB is hashedNo plain-text password
Session TimeoutRemain idle for 15+ minutesAuto logout
HTTPSAccess using http://Redirects to https://
SQL InjectionEnter ' OR '1'='1 in loginLogin fails

Test Report PDF: View Report

Security Feature Code: View Code

Security Testing Code: View Test Code

Screenshot Demo: View Demo Images

Web hosting by Somee.com