-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchange.php
90 lines (67 loc) · 3.18 KB
/
change.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
<?php
$pageTitle = "Change Password";
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
date_default_timezone_set('America/chicago');
require_once dirname(__FILE__) . '/lib/password.php';
require_once dirname(__FILE__).'/Model/DBController.php';
$objDBController = new DBController();
$dbconn=$objDBController->getConn();
// Was the form submitted?
if (isset($_POST["ForgotPassword"])) {
// Harvest submitted e-mail address
if (filter_var($_POST["email"], FILTER_VALIDATE_EMAIL)) {
$email = $_POST["email"];
}else{
include dirname(__FILE__) . '/views/header.php';
echo "email is not valid";
include dirname(__FILE__) . '/views/footer.php';
exit;
}
// Check to see if a user exists with this e-mail
$query = $dbconn->prepare('SELECT email FROM user WHERE email = :email');
$query->bindParam(':email', $email);
$query->execute();
$userExists = $query->fetch(PDO::FETCH_ASSOC);
$dbconn = null;
if ($userExists["email"])
{
require_once dirname(__FILE__) . '/vendor/swiftmailer/swiftmailer/lib/swift_required.php';
// Create a unique salt. This will never leave PHP unencrypted.
$salt = "498#2D83B631%3800EBD!801600D*7E3CC13";
// Create the unique user password reset key
$password = hash('sha512', $salt.$userExists["email"]);
// Create a url which we will direct them to reset their password
$pwrurl = (( (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on')) ? 'https://' : 'http://' ) .$_SERVER['HTTP_HOST'].dirname($_SERVER['REQUEST_URI'])."/reset_password.php?q=".$password;
$from = '[email protected]';
$to = $userExists["email"];
$subject = " Password Reset";
$body = 'Dear user,<br><br>
If this e-mail does not apply to you please ignore it. It appears that you have requested a password reset at our website https://datamed.org<br>
To reset your password, please click the link below. If you cannot click it, please paste it into your web browser\'s address bar.<br><br>'
. $pwrurl . '<br><br>Thanks,<br>The DataMed Team';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
->setUsername('[email protected]')
->setPassword('biocaddie4050@');
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('DataMed -' . $subject)
->setFrom(array($from => 'bioCaddie'))
->setTo(array($to))
->setBody($body)
->setContentType("text/html");
$result = $mailer->send($message);
include dirname(__FILE__) . '/views/header.php';
echo "<div class='container'>Your password recovery key has been sent to your e-mail address.</div>";
// header( "refresh:5;url=../index.php" );
include dirname(__FILE__) . '/views/footer.php';
}
else{
include dirname(__FILE__) . '/views/header.php';
echo "<div class='container'>No user with that e-mail address exists.</div>";
include dirname(__FILE__) . '/views/footer.php';
}
}else{
header('Location: index.php');
exit;
}
?>