forked from aqibos/CookbookNetwork
/
forgot-password-result.php
153 lines (131 loc) · 4.08 KB
/
forgot-password-result.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
session_start() ;
// define variables and set to empty values
$user_email = "";
$output ="" ;
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$user_email = test_input($_POST["email"]);
if (!filter_var($user_email, FILTER_VALIDATE_EMAIL))
{
$output = "Invalid email format";
}
else
{
$sent = send_to($user_email) ;
if($sent)
$output = "A password was sent to ".$user_email;
else
$output = $user_email." was not found in our system";
}
}
function test_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
function send_to($email)
{
include 'db-credentials.php' ;
$conn = new mysqli($servername, $username, $password, $dbname) or die("Unable to connect");
$sql = "SELECT * FROM Account WHERE email = '$email'" ;
$result = $conn -> query($sql) ;
if($result -> num_rows > 0)
{
$new_pw = generate_pw() ;
$sql = "UPDATE Account SET password='$new_pw' WHERE email='$email'" ;
if ($conn->query($sql) === TRUE)
{
$msg = "This is your new password. \n\nPassword:".$new_pw."\n\nPlease change your password through the 'Account Info' link as soon as possible!" ;
$msg = wordwrap($msg,70) ;
$worked = mail($email,"Cookbook Network: Reset Password",$msg,"From: localhost:81/127.0.0.1");
echo $worked ;
}
else
echo "Try again: Error updating record: " . $conn->error;
$conn -> close() ;
return true;
}
else
{
$conn -> close() ;
return false;
}
}
function generate_pw()
{
$valid_chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" ;
$pdubs = '' ;
for( $i = 0 ; $i < 20 ; $i++)
{
$pick = mt_rand( 0 , 61 ) ;
$pdubs .= $valid_chars[$pick] ;
}
return $pdubs ;
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="description" content="A virtual cookbook that allows user's to view, create and share recipes.">
<meta name="keywords" content="recipe, cookbook, food, ingredients">
<meta name="author" content="Cookbook Network Inc.">
<link rel="stylesheet" type="text/css" href="index_style-1.css">
<link href='http://fonts.googleapis.com/css?family=Tangerine:700' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=IM+Fell+Double+Pica' rel='stylesheet' type='text/css'>
<script type="text/javascript">
var image1 = new Image()
image1.src = "images/Pizza-Food-Delicious-1440x2560.jpg"
var image2 = new Image()
image2.src = "images/delicious-pizza-food-1440x900.jpg"
var image3 = new Image()
image3.src = "images/food_spaghetti_1920x1080_wallp_2560x1440_miscellaneoushi.com_.jpg"
var image4 = new Image()
image4.src = "images/Hot-and-Delicious-Food-Photos.jpg"
var image5 = new Image()
image5.src = "images/Food-Delicious-Pizza-Olives-Olives-1440x2560.jpg"
var image6 = new Image()
image6.src = "images/loaf-delicious-cake-with-strawberries-wallpapers-1440x900.jpg"
</script>
</head>
<body>
<p><img src="images/Pizza-Food-Delicious-1440x2560.jpg" name="slide" class="slideshow"/></p>
<div class="full-body">
<div class="content-transparent">
<div class="content">
<table class="content-table">
<tr>
<td class="content-table-left"><h1 class="content-table-left-header">Cookbook Network</h1></td>
<td class="content-table-right">
<h2><?php echo $output?></h2>
<a href="index-1.html"><button>Home</button></a>
<a href="forgot-password.php"><button>Back</button></a>
</td>
</tr>
<tr>
<td class="content-table-left">© Cookbook Network, 2015. All Rights Reserved.</td>
<td class="content-table-right"><i>Find, create, and share <u>millions</u> of recipes!</i></td>
</tr>
</table>
</div>
</div>
</div>
<!-- Slide Show -->
<script type="text/javascript">
var step=1;
function slideit()
{
document.images.slide.src = eval("image"+step+".src");
if(step<6)
step++;
else
step=1;
setTimeout("slideit()", 3000);
}
slideit();
</script>
</body>
</html>