-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_reset.php
More file actions
70 lines (55 loc) · 2.17 KB
/
process_reset.php
File metadata and controls
70 lines (55 loc) · 2.17 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
<?php
require_once("config.php");
require_once("send_mail.php");
if($_SERVER["REQUEST_METHOD"] == "POST") {
session_start();
$id = $_SESSION['userID'];
$password = $_SESSION['password'];
//echo $id, '-', $password;
$pwd = $_POST["password"];
$npwd = $_POST["new_password"];
$rpwd = $_POST["password_confirmation"];
if (empty($_POST['password']) || empty($_POST['new_password']) || empty($_POST['password_confirmation'])) {
echo('<script>alert("Please fill in all required information")</script>');
header("refresh:0;url=reset_password.php");
die();
}
if (password_verify($pwd, $password)) {
}
else {
echo('<script>alert("Incorrect Password")</script>');
header("refresh:0;url=reset_password.php");
die();
}
if ($pwd == $npwd){
echo('<script>alert("New password cannot the same with current password")</script>');
header("refresh:0;url=reset_password.php");
die();
}
if(strlen($npwd) < 6){
echo('<script>alert("Password must have at least 6 characters")</script>');
header("refresh:0;url=reset_password.php");
die();
}
if ($npwd != $rpwd) {
echo('<script>alert("New passwords do not match")</script>');
header("refresh:0;url=reset_password.php");
die();
}
$hashed_password = password_hash($npwd, PASSWORD_DEFAULT);
$sql = "UPDATE user SET password = '$hashed_password' WHERE user_id='$id'";
if (mysqli_query($link, $sql)) {
echo ('<script>alert("The password is changed successfully.")</script>');
$emails = "SELECT email FROM user WHERE user_id = '$id'";
$email_result = $link->query($emails);
while ($row = mysqli_fetch_array($email_result)) {
$email = $row['email'];
$subject = "Password Changed";
$body = "Hi there, <br/> <br/> The password for your Simple Click account has changed. <br/> <br/> Enjoy you journey at Simple Click! <br/> <br/> Kind regards, <br/> Simple Click Marketing Team <br/> ";
send_email($email, $subject, $body);
}
}
}
mysqli_close($link);
header("refresh:0;url=logout.php");
?>