-
Notifications
You must be signed in to change notification settings - Fork 0
/
reset-password.php
113 lines (96 loc) · 2.42 KB
/
reset-password.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
session_start();
include 'database/connect.php';
include 'functions.php';
include 'langCheck.php';
$email = $_POST['email'];
$flag = $_POST['flag'];
if($flag == 'user'){
if(empty($email)){
echo $lang['emailEmpty'];
exit();
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo $lang['emailInvalid'];
exit();
}
$query = $con->prepare("SELECT * FROM users WHERE email = ?");
$query->bind_param("s", $email);
$query->execute();
$query->store_result();
$nm = $query->num_rows;
$query->close();
if($nm == 0){
echo $lang['userWithMailNotExists'];
exit();
} else {
/* TODO: add text to lang.php */
$code = uniqid();
$to = $email;
$subject = "Password reset"; //email subject
$headers = "From: $yourEmail"; //this is your mail
$body = "Hello\n\nYou requested password reset!\n\n
Your new password is:\n\n
$code\n\n
Make sure to change password as soon as you login.\n
Thank you";
if(!mail($to, $subject, $body, $headers)){
echo $lang['mailError'];
exit();
}
else{
$pass = encrypt($code);
if($std = $con->prepare("UPDATE users SET password = ? WHERE email = ?")){
$std->bind_param("ss", $pass, $email);
$std->execute();
$std->close();
}
echo $lang['checkEmail'];
exit();
}
}
}else if($flag == 'admin'){
if(empty($email)){
echo $lang['emailEmpty'];
exit();
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)){
echo $lang['emailInvalid'];
exit();
}
$query = $con->prepare("SELECT * FROM admin WHERE email = ?");
$query->bind_param("s", $email);
$query->execute();
$query->store_result();
$nm = $query->num_rows;
$query->close();
if( $nm == 0 ) {
echo $lang['adminWithMailNotExists'];
exit();
} else {
/* TODO: add text to lang.php */
$code = uniqid();
$to = $email;
$subject = "Password reset"; //email subject
$headers = "From: $yourEmail"; //this is your mail
$body = "Hello Admin\n\nYou forgot your password again!\n\n
Your new password is:\n\n
$code\n\n
Make sure to change password as soon as you login.\n
Thank you";
if( !mail($to, $subject, $body, $headers) ) {
echo $lang['mailError'];
exit();
} else {
$pass = encrypt($code);
if($std = $con->prepare("UPDATE admin SET password = ? WHERE email = ?")){
$std->bind_param("ss", $pass, $email);
$std->execute();
$std->close();
}
echo $lang['checkEmail'];
exit();
}
}
}
?>