-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditProfileFunctions.inc.php
More file actions
87 lines (82 loc) · 3.44 KB
/
Copy patheditProfileFunctions.inc.php
File metadata and controls
87 lines (82 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
function emptySignupInput($oldPassword, $newPassword, $repeatNewPassword)
{
$result = false;
if (empty($oldPassword) || empty($newPassword) || empty($repeatNewPassword)) {
$result = true;
} else {
$result = false;
}
return $result;
}
function passwordMatch($newPassword, $repeatNewPassword)
{
$result = false;
if ($newPassword !== $repeatNewPassword) {
$result = true;
} else {
$result = false;
}
return $result;
}
function passwordStrength($newPassword)
{
$result = false;
$uppercase = preg_match('@[A-Z]@', $newPassword);
$lowercase = preg_match('@[a-z]@', $newPassword);
$number = preg_match('@[0-9]@', $newPassword);
if (!$uppercase || !$lowercase || !$number || strlen($newPassword) < 8) {
$result = true;
} else {
$result = false;
}
return $result;
}
function editUserProfile($conn, $newPassword, $oldPassword, $userUid)
{
$query = "SELECT * FROM teacher WHERE teacherUid='$userUid' OR teacherEmail='$userUid'";
$teacherExist = mysqli_query($conn, $query);
if (mysqli_num_rows($teacherExist) > 0) {
$row = mysqli_fetch_array($teacherExist);
$passwordHashed = $row["teacherPassword"];
$checkPassword = password_verify($oldPassword, $passwordHashed);
if ($checkPassword === false) {
header("location: ../profile.php?error=wrongloginpassword");
exit();
} elseif ($checkPassword === true) {
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$updateTeacherPassword = "UPDATE teacher SET teacherPassword='$hashedPassword' WHERE teacherUid='$userUid'";
$run = mysqli_query($conn, $updateTeacherPassword) or die("Query Unsuccessful.");
$updateUserPassword = "UPDATE users SET userPassword='$hashedPassword' WHERE userUid='$userUid'";
$run = mysqli_query($conn, $updateUserPassword) or die("Query Unsuccessful.");
header("location: ../profile.php?error=none");
mysqli_close($conn);
}
} else {
echo "query not working";
}
}
function editStudentProfile($conn, $newPassword, $oldPassword, $userUid)
{
$query = "SELECT * FROM student WHERE studentUid='$userUid' OR studentEmail='$userUid'";
$studentExist = mysqli_query($conn, $query);
if (mysqli_num_rows($studentExist) > 0) {
$row = mysqli_fetch_array($studentExist);
$passwordHashed = $row["studentPassword"];
$checkPassword = password_verify($oldPassword, $passwordHashed);
if ($checkPassword === false) {
header("location: ../studentdashboard.php?error=wrongloginpassword");
exit();
} elseif ($checkPassword === true) {
$hashedPassword = password_hash($newPassword, PASSWORD_DEFAULT);
$updateStudentPassword = "UPDATE student SET studentPassword='$hashedPassword' WHERE studentUid='$userUid'";
$run = mysqli_query($conn, $updateStudentPassword) or die("Query Unsuccessful.");
$updateUserPassword = "UPDATE users SET userPassword='$hashedPassword' WHERE userUid='$userUid'";
$run = mysqli_query($conn, $updateUserPassword) or die("Query Unsuccessful.");
header("location: ../studentdashboard.php?error=none");
mysqli_close($conn);
}
} else {
echo "query not working";
}
}