ILIAS  release_8 Revision v8.19-1-g4e8f2f9140c
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestPasswordChecker.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  protected $rbacsystem;
31 
35  protected $user;
36 
40  protected $testOBJ;
41 
45  protected $lng;
46 
48  {
49  $this->rbacsystem = $rbacsystem;
50  $this->user = $user;
51  $this->testOBJ = $testOBJ;
52  $this->lng = $lng;
53  }
54 
56  {
57  if (!$this->isTestPasswordEnabled()) {
58  return false;
59  }
60 
61  if ($this->isPrivilegedParticipant()) {
62  return false;
63  }
64 
65  if ($this->isUserEnteredPasswordCorrect()) {
66  return false;
67  }
68 
69  return true;
70  }
71 
72  protected function isTestPasswordEnabled(): int
73  {
74  return strlen($this->testOBJ->getPassword());
75  }
76 
77  protected function isPrivilegedParticipant(): bool
78  {
79  return $this->rbacsystem->checkAccess('write', $this->testOBJ->getRefId());
80  }
81 
82  public function wrongUserEnteredPasswordExist(): bool
83  {
84  if (!strlen($this->getUserEnteredPassword())) {
85  return false;
86  }
87 
88  return !$this->isUserEnteredPasswordCorrect();
89  }
90 
91  public function isUserEnteredPasswordCorrect(): bool
92  {
93  return $this->getUserEnteredPassword() == $this->testOBJ->getPassword();
94  }
95 
96  public function setUserEnteredPassword($enteredPassword)
97  {
98  ilSession::set($this->buildSessionKey(), $enteredPassword);
99  }
100 
101  protected function getUserEnteredPassword()
102  {
103  return ilSession::get($this->buildSessionKey());
104  }
105 
106  protected function buildSessionKey(): string
107  {
108  return 'tst_password_' . $this->testOBJ->getTestId();
109  }
110 
111  public function logWrongEnteredPassword()
112  {
114  return;
115  }
116 
118  $this->user->getId(),
119  $this->testOBJ->getId(),
121  null,
122  null,
123  true,
124  $this->testOBJ->getRefId()
125  );
126  }
127 
128  protected function getWrongEnteredPasswordLogMsg(): string
129  {
130  return $this->lng->txtlng(
131  'assessment',
132  'log_wrong_test_password_entered',
134  );
135  }
136 }
static get(string $a_var)
static _addLog( $user_id, $object_id, $logtext, $question_id=0, $original_id=0, $test_only=false, $test_ref_id=0)
Add an assessment log entry.
__construct(ilRbacSystem $rbacsystem, ilObjUser $user, ilObjTest $testOBJ, ilLanguage $lng)
setUserEnteredPassword($enteredPassword)
static set(string $a_var, $a_val)
Set a value.