summaryrefslogtreecommitdiff
path: root/src/lib/Login.class.php
blob: 28675f65b3794e36ef9c01c830fb45b43f77860b (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
<?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;
		$uid = $mm->database()->getUID($username);
		if ($uid===false) {
			// user does not exist
			return 2;
		}
		$hash = $mm->database()->getPasswordHash($uid);
		if ($mm->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'] = '';
	}
}