-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhandle_password.php
More file actions
68 lines (53 loc) · 1.78 KB
/
handle_password.php
File metadata and controls
68 lines (53 loc) · 1.78 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
<?php
if(!isset($_SESSION))
{
session_start();
}
require __DIR__.'/vendor/autoload.php';
// This assumes that you have placed the Firebase credentials in the same directory
// as this PHP file.
use Kreait\Firebase\Factory;
use Kreait\Firebase\ServiceAccount;
$serviceAccount = ServiceAccount::fromJsonFile(__DIR__.'/yss-project-69ba2-firebase-adminsdk-qpgd1-772443326e.json');
$firebase = (new Factory)
->withServiceAccount($serviceAccount)
->create();
$database = $firebase->getDatabase();
$reference = $database->getReference('/users')->getValue();
$comma_email = str_replace(".",",",$_POST['email']);
$redirectpagename = "new_password.php";
function alert($msg) {
echo "<script type='text/javascript'>alert('$msg');</script>";
}
echo $emailwcomma;
// if email not in database
if(!$reference[$comma_email]){
alert("This email is not in the database. Please try again.");
include $redirectpagename;
exit;
}
// if reset token not associated with email
else if ($reference[$comma_email]["token"] != $_POST['reset_token']){
alert("This reset token is not associated with this email address. Please try again.");
include $redirectpagename;
exit;
}
// check password comparison
else if($_POST['new_password'] != $_POST['new_password2']) {
alert("The passwords do not match. Please try again.");
include $redirectpagename;
exit;
}
// free to change password for user
else {
$updates = [
"/users/$comma_email/password" => $_POST['new_password'],
];
$database->getReference() // this is the root reference
->update($updates);
$database->getReference("/users/$comma_email/token")->remove();
alert("Your password has been changed successfully. Please log in to view your dashboard.");
include "login.php";
exit;
}
?>