ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilPDOAuthentication.php
Go to the documentation of this file.
1 <?php
2 
3 require_once 'Services/Authentication/classes/PDO/interface.ilAuthPDOInterface.php';
4 
9 {
10  protected $_sessionName = '_authsession';
11  protected $allowLogin = true;
12  protected $_postUsername = 'username';
13  protected $_postPassword = 'password';
14  protected $advancedsecurity;
15  protected $enableLogging;
17  protected $status = '';
18  protected $username = null;
19  protected $password;
20  protected $session;
21  protected $server;
22  protected $post;
23  protected $cookie;
24 
25 
26  public function __construct()
27  {
28  // $started = session_start();
29  // $sess = session_id();
30  // $db_session_handler = new ilSessionDBHandler();
31  // if (!$db_session_handler->setSaveHandler())
32  // {
33  // throw new Exception("Disable save mode or set session_hanlder to \"user\"");
34  // }
35  @session_start(); // Due to UnitTests we have to silence this...
36 
37  $this->session = $_SESSION[$this->_sessionName];
38  $this->server = $_SERVER;
39  $this->post = $_POST;
40  $this->cookie = $_COOKIE;
41  }
42 
43 
44  public function setIdle($time, $add = false)
45  {
46  // TODO: Implement setIdle() method.
47  }
48 
49 
56  public function setExpire($time, $add = false)
57  {
58  // TODO: Implement setExpire() method.
59  }
60 
61 
66  public function start()
67  {
68  // TODO SAME AS old AUTH
69  $this->assignData();
70  if (!$this->checkAuth() && $this->allowLogin) {
71  $this->login();
72  }
73  }
74 
75 
79  protected function checkAuth()
80  {
81  return isset($_SESSION['_authsession']['username']);
82  }
83 
84 
85  protected function login()
86  {
87  if (!empty($this->username) && $this->verifyPassword($this->username, $this->password)) {
88  $this->setAuth($this->username);
89  } else {
90  $this->status = AUTH_WRONG_LOGIN;
91  }
92  }
93 
94 
103  public function getAuth()
104  {
105  return $this->checkAuth();
106  }
107 
108 
112  public function getStatus()
113  {
114  return $this->status;
115  }
116 
117 
121  public function getUsername()
122  {
123  return $_SESSION['_authsession']['username'];
124  }
125 
126 
133  public function sessionValidThru()
134  {
135  return time() + 1000000;
136  }
137 
138 
139  public function logout()
140  {
141  $_SESSION['_authsession'] = null;
142  }
143 
144  protected function assignData()
145  {
146  if (isset($this->post[$this->_postUsername])
147  && $this->post[$this->_postUsername] != ''
148  ) {
149  $this->username = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postUsername]) : $this->post[$this->_postUsername]);
150  }
151  if (isset($this->post[$this->_postPassword])
152  && $this->post[$this->_postPassword] != ''
153  ) {
154  $this->password = (get_magic_quotes_gpc() == 1 ? stripslashes($this->post[$this->_postPassword]) : $this->post[$this->_postPassword]);
155  }
156  }
157 
158 
162  private function setAuth($username)
163  {
164  // session_regenerate_id(true); doesn't seem to work on PHP7
165 
166  if (!isset($_SESSION['_authsession'])) {
167  $_SESSION['_authsession'] = array();
168  }
169 
170  $_SESSION['_authsession']['username'] = $username;
171  }
172 
173 
179  private function verifyPassword($username, $password)
180  {
181  require_once 'Services/User/classes/class.ilUserPasswordManager.php';
182 
187  return ilUserPasswordManager::getInstance()->verifyPassword($user, $password);
188  }
189 }
sessionValidThru()
Returns the time up to the session is valid.
$_COOKIE['client_id']
Definition: server.php:9
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
$_SESSION["AccountId"]
setExpire($time, $add=false)
Set the maximum expire time.
$time
Definition: cron.php:21
static _loginExists($a_login, $a_user_id=0)
check if a login name already exists You may exclude a user from the check by giving his user id as 2...
start()
Start new auth session.
static getInstanceByObjId($a_obj_id, $stop_on_error=true)
get an instance of an Ilias object by object id
Create styles array
The data for the language used.
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
$_POST["username"]
static getInstance()
Single method to reduce footprint (included files, created instances)
getAuth()
Has the user been authenticated?
setIdle($time, $add=false)
Set maximum idle time.