-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword_new.php
48 lines (39 loc) · 1.31 KB
/
password_new.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
include 'session.php';
if (!isset($_GET['code']) or !isset($_GET['email'])) {
header('location: index.php');
exit();
}
$path = 'password_reset.php?code=' . $_GET['code'] . '&email=' . $_GET['email'];
if (isset($_POST['reset'])) {
$password = $_POST['password'];
$repassword = $_POST['repassword'];
if ($password != $repassword) {
$_SESSION['error'] = 'Passwords did not match';
header('location: ' . $path);
} else {
$conn = $pdo->open();
$stmt = $conn->prepare("SELECT *, COUNT(*) AS numrows FROM unibooker WHERE code=:code AND email=:email");
$stmt->execute(['code' => $_GET['code'], 'email' => $_GET['email']]);
$row = $stmt->fetch();
if ($row['numrows'] > 0) {
$password = password_hash($password, PASSWORD_DEFAULT);
try {
$stmt = $conn->prepare("UPDATE unibooker SET password=:password WHERE id=:id");
$stmt->execute(['password' => $password, 'id' => $row['id']]);
$_SESSION['success'] = 'Password successfully reset';
header('location: Signin');
} catch (PDOException $e) {
$_SESSION['error'] = $e->getMessage();
header('location: ' . $path);
}
} else {
$_SESSION['error'] = 'Code did not match with user';
header('location: ' . $path);
}
$pdo->close();
}
} else {
$_SESSION['error'] = 'Input new password first';
header('location: ' . $path);
}