19 declare(strict_types=1);
46 $query =
'SELECT EXISTS(SELECT 1 FROM usr_pwassist WHERE pwassist_id = %s) AS hit';
49 (
int) ($this->db->fetchAssoc(
64 $query =
'SELECT * FROM usr_pwassist WHERE user_id = ' . $this->db->quote(
68 $result = $this->db->query($query);
69 $row = $this->db->fetchAssoc($result);
71 return new Error(sprintf(
'No session found for usr_id %s', $usr_id->
toInt()));
86 $query =
'SELECT * FROM usr_pwassist WHERE pwassist_id = ' . $this->db->quote(
90 $result = $this->db->query($query);
91 $row = $this->db->fetchAssoc($result);
93 return new Error(sprintf(
'No session found for hash %s', $hash->
value()));
108 $query =
'DELETE FROM usr_pwassist ' .
111 $this->db->manipulate($query);
114 ->withCreationDateTime(
116 )->withExpirationDateTime(
117 $this->clock->now()->add(
new \
DateInterval(
'PT' . self::DEFAULT_LIFETIME_IN_SECONDS .
'S'))
120 $this->db->manipulateF(
121 'INSERT INTO usr_pwassist (pwassist_id, expires, user_id, ctime) VALUES (%s, %s, %s, %s)',
129 $session->hash()->value(),
130 $session->expirationDateTime()->getTimestamp(),
131 $session->usrId()->toInt(),
132 $session->creationDateTime()->getTimestamp()
141 $query =
'DELETE FROM usr_pwassist WHERE pwassist_id = ' . $this->db->quote(
142 $session->
hash()->value(),
145 $this->db->manipulate($query);
getSessionByUsrId(ObjectId $usr_id)
createSession(PasswordAssistanceHash $hash, ObjectId $usr_id)
const DEFAULT_LIFETIME_IN_SECONDS
getSessionByHash(PasswordAssistanceHash $hash)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static getBytes(int $length)
Generate random bytes using OpenSSL or Mcrypt and mt_rand() as fallback.
deleteSession(PasswordAssistanceSession $session)
__construct(private readonly \ilDBInterface $db, private readonly ClockInterface $clock)