forked from oys0317/fantastic-30-4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
saveNewPassword.php
48 lines (41 loc) · 1.36 KB
/
saveNewPassword.php
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
<?php
session_start();
$db = new PDO("mysql:host=localhost;dbname=fantastic304;port=3306","root");
$userID = $_COOKIE['userID'];
// Get the real current password
$userSQL = " SELECT Password
FROM User
WHERE UserID = '$userID'";
if(!$userSQL) {
echo "An error has happened!";
}
$realOldPassword = "";
foreach($db->query($userSQL) as $row) {
$realOldPassword = $row['Password'];
}
// Make sure user got old password correct and both new passwords match
$oldPass = $_POST['currentPasswordBox'];
$newPass0 = $_POST['newPasswordBox'];
$newPass1 = $_POST['otherNewPasswordBox'];
if($realOldPassword != $oldPass) {
$_SESSION['editPwdWrongPwd'] = TRUE; // Tells page to display 'incorrect pwd' text on reload
$_SESSION['editPwdNoMatch'] = FALSE;
header('Location: ./editPersonalInfo.php');
}
else if($newPass0 != $newPass1) {
$_SESSION['editPwdWrongPwd'] = FALSE;
$_SESSION['editPwdNoMatch'] = TRUE; // Tells page to display 'pwds dont match' text on reload
header('Location: ./editPersonalInfo.php');
// TODO: Tell user that new pwds don't match
}
// If password info makes sense, change user's password.
else {
// Change the user's password
$stmt = $db->prepare(" UPDATE User
SET Password=:NewPassword
WHERE UserID = '$userID'");
$stmt->bindParam(':NewPassword', $_POST['newPasswordBox']);
$stmt->execute();
header('Location: ./myaccount.php');
}
?>