ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
inc.pwassist_session_handler.php File Reference

Go to the source code of this file.

Functions

 db_pwassist_create_id ()
 Creates a new secure id. More...
 
 db_pwassist_session_read (string $pwassist_id)
 
 db_pwassist_session_find (int $user_id)
 
 db_pwassist_session_write (string $pwassist_id, int $maxlifetime, int $user_id)
 
 db_pwassist_session_destroy (string $pwassist_id)
 
 db_pwassist_session_gc ()
 

Function Documentation

◆ db_pwassist_create_id()

db_pwassist_create_id ( )

Creates a new secure id.

The secure id has the following characteristics:

  • It is unique
  • It is a non-uniformly distributed (pseudo) random value
  • Only a non-substantial number of bits can be predicted from previously generated id's.

Definition at line 30 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, ilPasswordUtils\getBytes(), ILIAS\Repository\int(), and ilDBConstants\T_TEXT.

Referenced by ilPasswordAssistanceGUI\submitAssistanceForm().

30  : string
31 {
32  global $DIC;
33 
34  $ilDB = $DIC->database();
35 
36  do {
37  $hash = bin2hex(ilPasswordUtils::getBytes(32));
38 
39  $exists = (
40  (int) ($ilDB->fetchAssoc(
41  $ilDB->query(
42  "SELECT EXISTS(" .
43  "SELECT 1 FROM usr_pwassist WHERE pwassist_id = " . $ilDB->quote($hash, ilDBConstants::T_TEXT) .
44  ") AS hit"
45  )
46  )['hit'] ?? 0) === 1
47  );
48  } while ($exists);
49 
50  return $hash;
51 }
global $DIC
Definition: shib_login.php:25
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ db_pwassist_session_destroy()

db_pwassist_session_destroy ( string  $pwassist_id)

Definition at line 103 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, $q, and ilDBConstants\T_TEXT.

Referenced by ilPasswordAssistanceGUI\submitAssignPasswordForm(), and ilSessionTest\testPasswordAssisstanceSession().

103  : void
104 {
105  global $DIC;
106 
107  $ilDB = $DIC->database();
108 
109  $q = 'DELETE FROM usr_pwassist WHERE pwassist_id = ' . $ilDB->quote($pwassist_id, ilDBConstants::T_TEXT);
110  $ilDB->manipulate($q);
111 }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
+ Here is the caller graph for this function:

◆ db_pwassist_session_find()

db_pwassist_session_find ( int  $user_id)
Returns
null|array{"pwassist_id": string, "expires": int|numeric-string, "user_id": int|numeric-string, "ctime": int|numeric-string}

Definition at line 71 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, $q, $r, and ilDBConstants\T_INTEGER.

Referenced by ilSessionTest\testPasswordAssisstanceSession().

71  : ?array
72 {
73  global $DIC;
74 
75  $ilDB = $DIC->database();
76 
77  $q = 'SELECT * FROM usr_pwassist WHERE user_id = ' . $ilDB->quote($user_id, ilDBConstants::T_INTEGER);
78  $r = $ilDB->query($q);
79 
80  return $ilDB->fetchAssoc($r);
81 }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
$r
+ Here is the caller graph for this function:

◆ db_pwassist_session_gc()

db_pwassist_session_gc ( )

Definition at line 114 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, $q, and ilDBConstants\T_INTEGER.

Referenced by ilSessionTest\testPasswordAssisstanceSession().

114  : void
115 {
116  global $DIC;
117 
118  $ilDB = $DIC->database();
119 
120  $q = 'DELETE FROM usr_pwassist WHERE expires < ' . $ilDB->quote(time(), ilDBConstants::T_INTEGER);
121  $ilDB->manipulate($q);
122 }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
+ Here is the caller graph for this function:

◆ db_pwassist_session_read()

db_pwassist_session_read ( string  $pwassist_id)
Returns
null|array{"pwassist_id": string, "expires": int|numeric-string, "user_id": int|numeric-string, "ctime": int|numeric-string}

Definition at line 56 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, $q, $r, and ilDBConstants\T_TEXT.

Referenced by ilPasswordAssistanceGUI\showAssignPasswordForm(), ilPasswordAssistanceGUI\submitAssignPasswordForm(), and ilSessionTest\testPasswordAssisstanceSession().

56  : ?array
57 {
58  global $DIC;
59 
60  $ilDB = $DIC->database();
61 
62  $q = 'SELECT * FROM usr_pwassist WHERE pwassist_id = ' . $ilDB->quote($pwassist_id, ilDBConstants::T_TEXT);
63  $r = $ilDB->query($q);
64 
65  return $ilDB->fetchAssoc($r);
66 }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
$r
+ Here is the caller graph for this function:

◆ db_pwassist_session_write()

db_pwassist_session_write ( string  $pwassist_id,
int  $maxlifetime,
int  $user_id 
)

Definition at line 83 of file inc.pwassist_session_handler.php.

References $DIC, $ilDB, $q, ilDBConstants\T_INTEGER, and ilDBConstants\T_TEXT.

Referenced by ilPasswordAssistanceGUI\submitAssistanceForm(), and ilSessionTest\testPasswordAssisstanceSession().

83  : void
84 {
85  global $DIC;
86 
87  $ilDB = $DIC->database();
88 
89  $q = 'DELETE FROM usr_pwassist ' .
90  'WHERE pwassist_id = ' . $ilDB->quote($pwassist_id, ilDBConstants::T_TEXT) . ' ' .
91  'OR user_id = ' . $ilDB->quote($user_id, ilDBConstants::T_INTEGER);
92  $ilDB->manipulate($q);
93 
94  $ctime = time();
95  $expires = $ctime + $maxlifetime;
96  $ilDB->manipulateF(
97  'INSERT INTO usr_pwassist (pwassist_id, expires, user_id, ctime) VALUES (%s, %s, %s, %s)',
99  [$pwassist_id, $expires, $user_id, $ctime]
100  );
101 }
global $DIC
Definition: shib_login.php:25
$q
Definition: shib_logout.php:18
+ Here is the caller graph for this function: