From 8876825ef93fcf40ab39160b321e2d52e6a2cc2a Mon Sep 17 00:00:00 2001 From: Aya Boussouf Date: Wed, 14 May 2025 17:43:36 +0000 Subject: [PATCH 1/3] Fix Bug48: Implememt Password Recovery Using Security Questions --- .gitignore | 5 +- AnswerSecurityQuestions.php | 87 +++++++++++ Header.php | 7 +- recover_password.php => RecoverPassword.php | 4 +- ResetPassword.php | 78 ++++++++++ Script.php | 114 +++++++++++--- SecurityQuestions.php | 139 +++++++++++++++++ index.php | 2 +- lrr_database.sql | 45 ++++-- test/SeleniumAya/helper.py | 37 +++++ test/SeleniumAya/test_bug48.py | 156 ++++++++++++++++++++ test/SeleniumHui/test_lrr.py | 32 ++-- test/conftest.py | 2 +- 13 files changed, 650 insertions(+), 58 deletions(-) create mode 100644 AnswerSecurityQuestions.php rename recover_password.php => RecoverPassword.php (75%) create mode 100644 ResetPassword.php create mode 100644 SecurityQuestions.php create mode 100644 test/SeleniumAya/helper.py create mode 100644 test/SeleniumAya/test_bug48.py diff --git a/.gitignore b/.gitignore index a0f0e53..d0ee3b1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ -.vscode -.DS_Store +venv/ +__pycache__/ +*.pyc diff --git a/AnswerSecurityQuestions.php b/AnswerSecurityQuestions.php new file mode 100644 index 0000000..7c78db4 --- /dev/null +++ b/AnswerSecurityQuestions.php @@ -0,0 +1,87 @@ +'; + } + } + + // Fetch security questions from the database for display + $sql = "SELECT question1, question2 FROM password_recovery_security_questions WHERE email = '$email'"; + $result = mysqli_query($con, $sql); + + if ($row = mysqli_fetch_assoc($result)) { + // Display the questions in a form + echo'


'; + echo '
'; + echo '
'; + echo '
'; + echo '
'; + if (isset($error_message)) { + echo ''; // Display error message + } + + //echo '
'; + echo '
'; + echo 'Answer Your Security Questions.'; + + // Question 1 + echo '
'; + echo ''; + echo ''; + echo '
'; + echo'
'; + + // Question 2 + echo '
'; + echo ''; + echo ''; + echo '
'; + + echo ''; + echo '
'; + echo '
'; // Close container + } else { + echo '
'; + } +} else { + header("Location: RecoverPassword.php"); // Redirect if session data is missing + exit; +} + +mysqli_close($con); +?> diff --git a/Header.php b/Header.php index 0733467..718a6b5 100644 --- a/Header.php +++ b/Header.php @@ -1,3 +1,8 @@ + + My courses "; } ?> diff --git a/recover_password.php b/RecoverPassword.php similarity index 75% rename from recover_password.php rename to RecoverPassword.php index 7eb2656..373eaba 100644 --- a/recover_password.php +++ b/RecoverPassword.php @@ -15,11 +15,9 @@ include 'Header.php';
Recover password - Student number -
Email
- +
diff --git a/ResetPassword.php b/ResetPassword.php new file mode 100644 index 0000000..aa17765 --- /dev/null +++ b/ResetPassword.php @@ -0,0 +1,78 @@ +Password must be at least 8 characters long and include uppercase and lowercase letters, numbers, and special characters.'; + } elseif ($new_password !== $confirm_password) { + echo '
Passwords do not match. Please try again.
'; + } else { + $hashed_password = password_hash($new_password, PASSWORD_ARGON2ID); + $user_id = $_SESSION['user_id']; + + $stmt = $con->prepare("UPDATE users_table SET Password = ? WHERE email = ? AND user_id = ?"); + $stmt->bind_param("sss", $hashed_password, $email, $user_id); + + if ($stmt->execute()) { + echo '
Password reset successfully. You can now log in with your new password.
'; + unset($_SESSION['user_id']); // Clear user_id after successful password reset + header("Location: index.php"); + } else { + error_log("Error updating password for user ID: $user_id"); + echo '
An error occurred. Please try again later.
'; + } + $stmt->close(); + } + } +} + +// Display the reset password form +echo ' +


+
+
+
+
+
+ Reset Your Password
+ New Password + +
+ Confirm New Password + +
+ +
+
+