blob: a470176f8f8243ab6d752d5342c5ffc30c6753b5 (
plain)
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
|
<?php
require_once('Database.class.php');
require_once('Hasher.class.php');
class Login {
/** Decalare an empty __construct() so that the login function doesn't
get mistaken for the costructor. */
public function __construct() {}
public static function login($username, $password) {
$db = Database::getInstance();
$hasher = Hasher::getInstance();
$uid = $db->getUID($username);
if ($uid!==false && $db->getStatus($uid)>=3)
$uid=false;
if ($uid===false) {
// user does not exist
return 2;
}
$hash = $db->getPasswordHash($uid);
if ($hasher->CheckPassword($password, $hash)) {
// success
$_SESSION['uid'] = $uid;
return 0;
} else {
// wrong password
return 1;
}
}
public static function isLoggedIn() {
if ( isset($_SESSION['uid']) && ($_SESSION['uid']!='') ) {
return $_SESSION['uid'];
} else {
return false;
}
}
public static function logout() {
$_SESSION['uid'] = '';
}
}
|