summaryrefslogtreecommitdiff
path: root/src/lib/Login.class.php
blob: 14e3ecb6ce73c2583f40aeb35914d6e875bb04ac (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
<?php

class Login {
	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'] = '';
	}
}