-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.php
196 lines (147 loc) · 6.5 KB
/
login.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
<?php
include "inc/init.php";
if($user->islg()) { // if it's alreadt logged in redirect to the main page
header("Location: $set->url");
exit;
}
$page->title = "Login to ". $set->site_name;
if($_POST && isset($_SESSION['token']) && ($_SESSION['token'] == $_POST['token'])) {
// we validate the data
if(isset($_GET['forget'])) {
$email = $_POST['email'];
if(!$options->isValidMail($email))
$page->error = "Email address is not valid.";
if(!isset($page->error) && !($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `email` = ?s", $email)))
$page->error = "This email address doesn't exist in our database !";
if(!isset($page->error)) {
$key = sha1(rand());
$db->query("UPDATE `".MLS_PREFIX."users` SET `key` = ?s WHERE `userid` = ?i", $key, $usr->userid);
$link = $set->url."/login.php?key=".$key."&userid=".$usr->userid;
$from ="From: not.reply@".$set->url;
$sub = "New Password !";
$msg = "Hello,<br> You requested for a new password. To confirm <a href='$link'>click here</a>.<br>If you can't access copy this to your browser<br/>$link <br><br>Regards<br><small>Note: Dont reply to this email. If you got this email by mistake then ignore this email.</small>";
if($options->sendMail($email, $sub, $msg, $from))
$page->success = "An email with instructions was sent !";
}
} else if(isset($_GET['key'])) {
if($_GET['key'] == '0') {
header("Location: $set->url");
exit;
}
if($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `key` = ?s", $_GET['key'])) {
if($db->query("UPDATE `".MLS_PREFIX."users` SET `password` = ?s WHERE `userid` = ?i", sha1($_POST['password']), $usr->userid)) {
$db->query("UPDATE `".MLS_PREFIX."users` SET `key` = '0' WHERE `userid` = ?i", $usr->userid);
$page->success = "Password was updated !";
}
}
} else {
$name = $_POST['name'];
$password = $_POST['password'];
if(!($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `username` = ?s AND `password` = ?s", $name, sha1($password))))
$page->error = "Username or password are wrong !";
else {
if($_POST['r'] == 1){
$path_info = parse_url($set->url);
setcookie("user", $name, time() + 3600 * 24 * 30, $path_info['path']); // set
setcookie("pass", sha1($password), time() + 3600 * 24 * 30, $path_info['path']); // set
}
$_SESSION['user'] = $usr->userid;
header("Location: $set->url");
exit;
}
}
} else if($_POST)
$page->error = "Invalid request !";
include 'header.php';
$_SESSION['token'] = sha1(rand()); // random token
echo "<div class='container'>
<div class='row'>
<div class='span3 hidden-phone'></div>
<div class='span6' id='form-login'>";
if(isset($page->error))
$options->error($page->error);
else if(isset($page->success))
$options->success($page->success);
if(isset($_GET['forget'])) {
echo "<form class='form-horizontal well' action='#' method='post'>
<fieldset>
<legend>Recover</legend>
<div class='control-group'>
<div class='control-label'>
<label>Email</label>
</div>
<div class='controls'>
<input type='text' placeholder='[email protected]' name='email' class='input-large'>
</div>
</div>
<input type='hidden' name='token' value='".$_SESSION['token']."'>
<div class='control-group'>
<div class='controls'>
<button type='submit' id='submit' class='btn btn-primary'>Recover</button>
</div>
</div>
</fieldset>";
} else if(isset($_GET['key']) && !isset($page->success)) {
if($_GET['key'] == '0') {
echo "<div class=\"alert alert-error\">Error !</div>";
exit;
}
if($usr = $db->getRow("SELECT `userid` FROM `".MLS_PREFIX."users` WHERE `key` = ?s AND `userid` = ?i", $_GET['key'], $_GET['userid'])) {
echo "<form class='form-horizontal well' action='#' method='post'>
<fieldset>
<legend>Reset</legend>
<div class='control-group'>
<div class='control-label'>
<label>New password</label>
</div>
<div class='controls'>
<input type='password' name='password' class='input-large'>
</div>
</div>
<input type='hidden' name='token' value='".$_SESSION['token']."'>
<div class='control-group'>
<div class='controls'>
<button type='submit' id='submit' class='btn btn-primary'>Save</button>
</div>
</div>
</fieldset>";
} else {
echo "<div class=\"alert alert-error\">Error bad key !</div>";
}
}else {
echo "<form class='form-horizontal well' action='?' method='post'>
<fieldset>
<legend>Login Form</legend>
<div class='control-group'>
<div class='control-label'>
<label>Username</label>
</div>
<div class='controls'>
<input type='text' placeholder='peter.ndebi' name='name' class='input-large'>
</div>
</div>
<div class='control-group'>
<div class='control-label'>
<label>Password</label>
</div>
<div class='controls'>
<input type='password' placeholder='type your password' name='password' class='input-large'>
<!-- Help-block example -->
<!-- <span class='help-block'>Example block-level help text here.</span> -->
</div>
</div>
<div class='control-group'>
</div>
<input type='hidden' name='token' value='".$_SESSION['token']."'>
<div class='control-group'>
<div class='controls'>
<button type='submit' id='submit' class='btn btn-primary'>Sign in</button>
<a href='?forget=1' class='btn btn-secondary'>Forgot Password</a>
</div>
</div>
</fieldset>";
}
echo " </form>
</div>
</div>";
?>