ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
inc.pwassist_session_handler.php
Go to the documentation of this file.
1 <?php
11 /*
12  +-----------------------------------------------------------------------------+
13  | ILIAS open source |
14  +-----------------------------------------------------------------------------+
15  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
16  | |
17  | This program is free software; you can redistribute it and/or |
18  | modify it under the terms of the GNU General Public License |
19  | as published by the Free Software Foundation; either version 2 |
20  | of the License, or (at your option) any later version. |
21  | |
22  | This program is distributed in the hope that it will be useful, |
23  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
24  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
25  | GNU General Public License for more details. |
26  | |
27  | You should have received a copy of the GNU General Public License |
28  | along with this program; if not, write to the Free Software |
29  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
30  +-----------------------------------------------------------------------------+
31 */
32 
33 
34 /*
35 * open session, normally a db connection would be opened here, but
36 * we use the standard ilias db connection, so nothing must be done here
37 *
38 * @param string $save_pathDSN information about how to access the database, format:
39 * dbtype(dbsyntax)://username:password@protocol+hostspec/database
40 * eg. mysql://phpsessmgr:topsecret@db.example.com/sessiondb
41 * @param string $name session name [session_name()]
42 */
43 function db_pwassist_session_open($save_path, $name)
44 {
45  return true;
46 }
47 
54 {
55  return true;
56 }
57 
58 /*
59 * Creates a new secure id.
60 *
61 * The secure id has the following characteristics:
62 * - It is unique
63 * - It is a non-uniformly distributed (pseudo) random value
64 * - Only a non-substantial number of bits can be predicted from
65 * previously generated id's.
66 */
68 {
69  // #26009 we use ilSession to duplicate the existing session
70  return \ilSession::_duplicate(session_id());
71 }
72 
73 /*
74 * Reads data of the session identified by $pwassist_id and returns it as a
75 * associative array. If there is no session with this ID an empty array is
76 * returned
77 *
78 * @param integer $pwassist_id secure id
79 */
80 function db_pwassist_session_read($pwassist_id)
81 {
82  global $DIC;
83 
84  $ilDB = $DIC->database();
85 
86  $q = "SELECT * FROM usr_pwassist " .
87  "WHERE pwassist_id = " . $ilDB->quote($pwassist_id, "text");
88  $r = $ilDB->query($q);
89  $data = $ilDB->fetchAssoc($r);
90 
91  return $data;
92 }
93 
94 /*
95 * Reads data of the session identified by $user_id.
96 * Teturns the data as an associative array.
97 * If there is no session for the specified user_id, an
98 * empty array is returned
99 *
100 * @param integer $user_id user id
101 **/
102 function db_pwassist_session_find($user_id)
103 {
104  global $DIC;
105 
106  $ilDB = $DIC->database();
107 
108  $q = "SELECT * FROM usr_pwassist " .
109  "WHERE user_id = " . $ilDB->quote($user_id, "integer");
110  $r = $ilDB->query($q);
111  $data = $ilDB->fetchAssoc($r);
112 
113  return $data;
114 }
115 
123 function db_pwassist_session_write($pwassist_id, $maxlifetime, $user_id)
124 {
125  global $DIC;
126 
127  $ilDB = $DIC->database();
128 
129  $q = "DELETE FROM usr_pwassist " .
130  "WHERE pwassist_id = " . $ilDB->quote($pwassist_id, "text") . " " .
131  "OR user_id = " . $ilDB->quote($user_id, 'integer');
132  $ilDB->manipulate($q);
133 
134  $ctime = time();
135  $expires = $ctime + $maxlifetime;
136  $ilDB->manipulateF(
137  "INSERT INTO usr_pwassist " .
138  "(pwassist_id, expires, user_id, ctime) " .
139  "VALUES (%s,%s,%s,%s)",
140  array("text", "integer", "integer", "integer"),
141  array($pwassist_id, $expires, $user_id, $ctime)
142  );
143 
144  return true;
145 }
146 
152 function db_pwassist_session_destroy($pwassist_id)
153 {
154  global $DIC;
155 
156  $ilDB = $DIC->database();
157 
158  $q = "DELETE FROM usr_pwassist " .
159  "WHERE pwassist_id = " . $ilDB->quote($pwassist_id, "text");
160  $ilDB->manipulate($q);
161 
162  return true;
163 }
164 
165 
170 {
171  global $DIC;
172 
173  $ilDB = $DIC->database();
174 
175  $q = "DELETE FROM usr_pwassist " .
176  "WHERE expires < " . $ilDB->quote(time(), "integer");
177  $ilDB->manipulate($q);
178 
179  return true;
180 }
db_pwassist_session_destroy($pwassist_id)
destroy session
db_pwassist_session_read($pwassist_id)
global $DIC
Definition: saml.php:7
$r
Definition: example_031.php:79
db_pwassist_session_find($user_id)
db_pwassist_session_gc()
removes all expired sessions
global $ilDB
db_pwassist_session_close()
close session
db_pwassist_session_open($save_path, $name)
Database Session Handling for the password assistance use case.
db_pwassist_session_write($pwassist_id, $maxlifetime, $user_id)
Writes serialized session data to the database.
$data
Definition: bench.php:6