-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforgot_password.php
More file actions
57 lines (56 loc) · 1.73 KB
/
forgot_password.php
File metadata and controls
57 lines (56 loc) · 1.73 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
<?php
require_once 'templates/page_setup.php';
$title = "Forgot Password";
$page_name = "forgotpassword";
$users = User::readUsers();
include 'templates/header.php';
include 'templates/jumbotron.php';
echo '
</head>
<body>
<div class="header">
<h2> Your password is being reset.</h2>
</div>
';
$str="";
if(isset($_POST['forgot_password'])){
$che = strip_tags(filter_var($_POST['email'],FILTER_SANITIZE_EMAIL));
if(User::checkEmail($users,$che)){
$_SESSION['email'] = $che;
$email = $che;
$password = $_SESSION['randkey'];
$pwrurl = "www.cs.colostate.edu/~mjrerle/p2/passwordreset.php?q=".$password;
$user = $_POST['username'];
$mailbody = "Hello $user, here is the link: ".$pwrurl;
if(mail($email, "www.cs.colostate.edu/~mjrerle - Password Reset", $mailbody)){
echo "Your password recovery key has been sent to your email address";
}
else{
echo "Failed to send email";
}
}
else{
echo 'Email given does not match the one on record! Try again? <a href="forgot_password.php">Click here</a>';
}
}
else {
echo '
<div class="contents">
<p>Select your username and enter your email</p>
<form action = "forgot_password.php" method = "post">
<select name = "username">
';
foreach ($users as $u) {
$flag = ($u->username == $_SESSION['username']) ? 'selected' : '';
echo "\t\t\t\t<option value=\"$u->username\" $flag > $u->username </option>\n";
}
echo '
</select><br>
Email Address: <input type = "text" name = "email"><br>
<input type = "submit" name = "forgot_password" value ="Request Reset">';
echo '<br>
</form>
';
}
include 'templates/footer.php';
?>