summaryrefslogtreecommitdiff
path: root/apps/um/lib/Login.class.php
diff options
context:
space:
mode:
Diffstat (limited to 'apps/um/lib/Login.class.php')
-rw-r--r--apps/um/lib/Login.class.php41
1 files changed, 41 insertions, 0 deletions
diff --git a/apps/um/lib/Login.class.php b/apps/um/lib/Login.class.php
new file mode 100644
index 0000000..bb21928
--- /dev/null
+++ b/apps/um/lib/Login.class.php
@@ -0,0 +1,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->check($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'] = '';
+ }
+}