-
Notifications
You must be signed in to change notification settings - Fork 0
/
Authenticator.php
executable file
·60 lines (50 loc) · 1.45 KB
/
Authenticator.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
<?php
require_once 'fbl_common.php';
class Authenticator {
private $username;
private $password;
function __construct($username, $password) {
$this->username = $username;
$this->password = $password;
}
function success_redirect() {
$_SESSION["email"] = $_POST["email"];
header("HTTP/1.1 303 See Other");
header('Location: home.php');
}
function fail_redirect() {
header("HTTP/1.1 307 Temporary Redirect");
header('Location: login.php?failed=1');
}
function do_login() {
if (!isset($_SESSION['email'])) { // absolutely not secure, use a token
$result = $this->authenticate();
}
else {
// Already logged in
$result = "Auth successful";
}
return $result;
}
private function authenticate() {
db_connect($client);
$collection = $client->fbl->Members;
$doc = $collection->findOne(["_id" => $this->username],
["projection" => [
"password_sum" => 1,
"password_salt" => 1
]]
);
if ($doc == null) {
return "No such user";
}
if (!check_password($this->password, hex2bin($doc["password_salt"]),
hex2bin($doc["password_sum"])))
{
return "No such password";
}
// success
return "Auth successful";
}
}
?>