-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword.php
More file actions
24 lines (22 loc) · 874 Bytes
/
password.php
File metadata and controls
24 lines (22 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?php
session_start();
$conn = new mysqli("localhost", "georgegarber", "password", "marketanalysisdb");
//select the user's row from the database
$users = $conn->query("select * from usertbl where userid=".$_SESSION['userid']);
$user = $users->fetch_assoc();
//if the password is correct
if (password_verify($_POST['oldpass'], $user['password'])) {
//update the password, and issue an alert
$conn->query('update usertbl set password="'.password_hash($_POST['newpass'], PASSWORD_DEFAULT).'" where userid='.$_SESSION['userid']);
echo "<script>
window.alert('Password Updated');
window.location.href = 'settings.php';
</script>";
} else {
//if the password's wrong issue an alert and return to the settings page
echo "<script>
window.alert('Password Incorrect');
window.location.href = 'settings.php';
</script>";
}
?>