Mercurial > owls
view Includes/Loginsys.class.php @ 7:a3a651f0cac6
added doxygen-comments to Loginsys.class.php
author | Meillo r e t u r n s <meillo@marmaro.de> |
---|---|
date | Wed, 13 Dec 2006 22:16:59 +0100 |
parents | 3021ce32ee14 |
children | eb5bff360deb |
line wrap: on
line source
<?php /** * simple loginsystem for owls * * @brief simple loginsystem for owls * @author Meillo r e t u r n s <meillo@marmaro.de> */ class Loginsys { /// Consts /** * time in seconds till the session expires */ define('TIME_SESSION_EXPIRES', 1800); /// Constructors /** * starts the session * and puts an activity timestamp in it */ public function __construct() { session_start(); $this->heartbeat(); } /// Methods /** * trys to log in with the given login data * * @param $loginname username * @param $password_md5 md5 password hash */ public function login($loginname, $password_md5) { // login ------------------------------------ $rowuser = mysql_fetch_array(mysql_query("select * from ". DB_PREFIX ."User where loginname='$loginname' and password='$password_md5' ")); if (mysql_affected_rows() == 1) { // valid login $_SESSION[login][id] = $rowuser[id]; $_SESSION[login][loginname] = $loginname; $_SESSION[login][logintime] = time(); } } /** * logs the user out */ public function logout() { // logout ------------------------------------------------------------ unset($_SESSION[login]); } /** * proves if the user is logged in and if he wan't to long inactive * * @return bool 'true' if user is logged in, else 'false' */ public function loggedIn() { // return login-status --------------------------------------------- return (isset($_SESSION[login][id]) && $_SESSION[login][logintime] > time()-TIME_SESSION_EXPIRES); } /** * writes the current timestamp into the session * this is relevant for the time of inactivity */ public function heartbeat() { if ($this->loggedIn()) { $_SESSION[login][logintime] = time(); } } /// Getter and Setter /** * @return user id */ public function getUserId() { return $_SESSION[login][id]; } /** * @return user name */ public function getLoginname() { return $_SESSION[login][loginname]; } } ?>