-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreset_password.php
More file actions
33 lines (27 loc) · 927 Bytes
/
reset_password.php
File metadata and controls
33 lines (27 loc) · 927 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
25
26
27
28
29
30
31
32
33
<?php
session_start();
require 'functions.php';
if(isset($_SESSION["login"])){
header("Location: user.php");
exit;
}
if(isset($_GET['email']) && !empty($_GET['email']) AND isset($_GET['code']) && !empty($_GET['code'])){
// Verify data
$email = $_GET['email'];
$code = $_GET['code'];
$searchCode = mysqli_query($conn, "SELECT * FROM reset_password WHERE code='$code'");
$search = mysqli_query($conn, "SELECT * FROM user WHERE email='$email'");
if(mysqli_num_rows($searchCode) === 1 && mysqli_num_rows($search) === 1){
$users = mysqli_fetch_assoc($search);
$pw = password_hash($code, PASSWORD_DEFAULT);
$query = mysqli_query($conn, "UPDATE user SET password='$pw' WHERE email='$email'");
if($query){
mysqli_query($conn, "DELETE FROM reset_password WHERE code = '$code'");
$_SESSION["login"] = true;
$_SESSION["id"] = $users["id"];
header("Location: user.php");
exit;
}
}
}
?>