blob: 870774aa232269d997634ba782a9bf29674d3413 (
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
|
<?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) {
global $mm;
$db = $mm->database();
$hasher = $mm->hasher();
$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'] = '';
}
}
|