@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | public function __destruct() { |
70 | 70 | try { |
71 | 71 | $this->close(); |
72 | - } catch (SessionNotAvailableException $e){ |
|
72 | + } catch (SessionNotAvailableException $e) { |
|
73 | 73 | // This exception can occur if session is already closed |
74 | 74 | // So it is safe to ignore it and let the garbage collector to proceed |
75 | 75 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | * @return string|null Either the value or null |
106 | 106 | */ |
107 | 107 | public function get(string $key) { |
108 | - if(isset($this->sessionValues[$key])) { |
|
108 | + if (isset($this->sessionValues[$key])) { |
|
109 | 109 | return $this->sessionValues[$key]; |
110 | 110 | } |
111 | 111 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | * Close the session and release the lock, also writes all changed data in batch |
172 | 172 | */ |
173 | 173 | public function close() { |
174 | - if($this->isModified) { |
|
174 | + if ($this->isModified) { |
|
175 | 175 | $encryptedValue = $this->crypto->encrypt(json_encode($this->sessionValues), $this->passphrase); |
176 | 176 | $this->session->set(self::encryptedSessionName, $encryptedValue); |
177 | 177 | $this->isModified = false; |
@@ -170,12 +170,12 @@ |
||
170 | 170 | */ |
171 | 171 | private function invoke(string $functionName, array $parameters = [], bool $silence = false) { |
172 | 172 | try { |
173 | - if($silence) { |
|
173 | + if ($silence) { |
|
174 | 174 | return @call_user_func_array($functionName, $parameters); |
175 | 175 | } else { |
176 | 176 | return call_user_func_array($functionName, $parameters); |
177 | 177 | } |
178 | - } catch(\Error $e) { |
|
178 | + } catch (\Error $e) { |
|
179 | 179 | $this->trapError($e->getCode(), $e->getMessage()); |
180 | 180 | } |
181 | 181 | } |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return bool |
82 | 82 | */ |
83 | 83 | public function verify(array $data): bool { |
84 | - if(isset($data['message']) |
|
84 | + if (isset($data['message']) |
|
85 | 85 | && isset($data['signature']) |
86 | 86 | && isset($data['message']['signer']) |
87 | 87 | ) { |
@@ -89,9 +89,9 @@ discard block |
||
89 | 89 | $userId = substr($data['message']['signer'], 0, $location); |
90 | 90 | |
91 | 91 | $user = $this->userManager->get($userId); |
92 | - if($user !== null) { |
|
92 | + if ($user !== null) { |
|
93 | 93 | $key = $this->keyManager->getKey($user); |
94 | - return (bool)openssl_verify( |
|
94 | + return (bool) openssl_verify( |
|
95 | 95 | json_encode($data['message']), |
96 | 96 | base64_decode($data['signature']), |
97 | 97 | $key->getPublic(), |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | $this->config = $config; |
63 | 63 | |
64 | 64 | $hashingCost = $this->config->getSystemValue('hashingCost', null); |
65 | - if(!\is_null($hashingCost)) { |
|
65 | + if (!\is_null($hashingCost)) { |
|
66 | 66 | $this->options['cost'] = $hashingCost; |
67 | 67 | } |
68 | 68 | } |
@@ -77,9 +77,9 @@ discard block |
||
77 | 77 | */ |
78 | 78 | public function hash(string $message): string { |
79 | 79 | if (\defined('PASSWORD_ARGON2I')) { |
80 | - return 2 . '|' . password_hash($message, PASSWORD_ARGON2I, $this->options); |
|
80 | + return 2.'|'.password_hash($message, PASSWORD_ARGON2I, $this->options); |
|
81 | 81 | } else { |
82 | - return 1 . '|' . password_hash($message, PASSWORD_BCRYPT, $this->options); |
|
82 | + return 1.'|'.password_hash($message, PASSWORD_BCRYPT, $this->options); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | |
@@ -90,9 +90,9 @@ discard block |
||
90 | 90 | */ |
91 | 91 | protected function splitHash(string $prefixedHash) { |
92 | 92 | $explodedString = explode('|', $prefixedHash, 2); |
93 | - if(\count($explodedString) === 2) { |
|
94 | - if((int)$explodedString[0] > 0) { |
|
95 | - return ['version' => (int)$explodedString[0], 'hash' => $explodedString[1]]; |
|
93 | + if (\count($explodedString) === 2) { |
|
94 | + if ((int) $explodedString[0] > 0) { |
|
95 | + return ['version' => (int) $explodedString[0], 'hash' => $explodedString[1]]; |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * @return bool Whether $hash is a valid hash of $message |
108 | 108 | */ |
109 | 109 | protected function legacyHashVerify($message, $hash, &$newHash = null): bool { |
110 | - if(empty($this->legacySalt)) { |
|
110 | + if (empty($this->legacySalt)) { |
|
111 | 111 | $this->legacySalt = $this->config->getSystemValue('passwordsalt', ''); |
112 | 112 | } |
113 | 113 | |
114 | 114 | // Verify whether it matches a legacy PHPass or SHA1 string |
115 | 115 | $hashLength = \strlen($hash); |
116 | - if(($hashLength === 60 && password_verify($message.$this->legacySalt, $hash)) || |
|
116 | + if (($hashLength === 60 && password_verify($message.$this->legacySalt, $hash)) || |
|
117 | 117 | ($hashLength === 40 && hash_equals($hash, sha1($message)))) { |
118 | 118 | $newHash = $this->hash($message); |
119 | 119 | return true; |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | * @return bool Whether $hash is a valid hash of $message |
131 | 131 | */ |
132 | 132 | protected function verifyHashV1(string $message, string $hash, &$newHash = null): bool { |
133 | - if(password_verify($message, $hash)) { |
|
133 | + if (password_verify($message, $hash)) { |
|
134 | 134 | $algo = PASSWORD_BCRYPT; |
135 | 135 | if (\defined('PASSWORD_ARGON2I')) { |
136 | 136 | $algo = PASSWORD_ARGON2I; |
137 | 137 | } |
138 | 138 | |
139 | - if(password_needs_rehash($hash, $algo, $this->options)) { |
|
139 | + if (password_needs_rehash($hash, $algo, $this->options)) { |
|
140 | 140 | $newHash = $this->hash($message); |
141 | 141 | } |
142 | 142 | return true; |
@@ -153,8 +153,8 @@ discard block |
||
153 | 153 | * @return bool Whether $hash is a valid hash of $message |
154 | 154 | */ |
155 | 155 | protected function verifyHashV2(string $message, string $hash, &$newHash = null) : bool { |
156 | - if(password_verify($message, $hash)) { |
|
157 | - if(password_needs_rehash($hash, PASSWORD_ARGON2I, $this->options)) { |
|
156 | + if (password_verify($message, $hash)) { |
|
157 | + if (password_needs_rehash($hash, PASSWORD_ARGON2I, $this->options)) { |
|
158 | 158 | $newHash = $this->hash($message); |
159 | 159 | } |
160 | 160 | return true; |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | public function verify(string $message, string $hash, &$newHash = null): bool { |
173 | 173 | $splittedHash = $this->splitHash($hash); |
174 | 174 | |
175 | - if(isset($splittedHash['version'])) { |
|
175 | + if (isset($splittedHash['version'])) { |
|
176 | 176 | switch ($splittedHash['version']) { |
177 | 177 | case 2: |
178 | 178 | return $this->verifyHashV2($message, $splittedHash['hash'], $newHash); |
@@ -76,7 +76,7 @@ |
||
76 | 76 | $maxCharIndex = \strlen($characters) - 1; |
77 | 77 | $randomString = ''; |
78 | 78 | |
79 | - while($length > 0) { |
|
79 | + while ($length > 0) { |
|
80 | 80 | $randomNumber = \random_int(0, $maxCharIndex); |
81 | 81 | $randomString .= $characters[$randomNumber]; |
82 | 82 | $length--; |
@@ -57,7 +57,7 @@ |
||
57 | 57 | */ |
58 | 58 | public function getToken(): string { |
59 | 59 | $token = $this->session->get('requesttoken'); |
60 | - if(empty($token)) { |
|
60 | + if (empty($token)) { |
|
61 | 61 | throw new \Exception('Session does not contain a requesttoken'); |
62 | 62 | } |
63 | 63 |
@@ -52,9 +52,9 @@ |
||
52 | 52 | * @return string |
53 | 53 | */ |
54 | 54 | public function getEncryptedValue(): string { |
55 | - if($this->encryptedValue === '') { |
|
55 | + if ($this->encryptedValue === '') { |
|
56 | 56 | $sharedSecret = random_bytes(\strlen($this->value)); |
57 | - $this->encryptedValue = base64_encode($this->value ^ $sharedSecret) . ':' . base64_encode($sharedSecret); |
|
57 | + $this->encryptedValue = base64_encode($this->value ^ $sharedSecret).':'.base64_encode($sharedSecret); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | return $this->encryptedValue; |
@@ -54,11 +54,11 @@ discard block |
||
54 | 54 | * @return CsrfToken |
55 | 55 | */ |
56 | 56 | public function getToken(): CsrfToken { |
57 | - if(!\is_null($this->csrfToken)) { |
|
57 | + if (!\is_null($this->csrfToken)) { |
|
58 | 58 | return $this->csrfToken; |
59 | 59 | } |
60 | 60 | |
61 | - if($this->sessionStorage->hasToken()) { |
|
61 | + if ($this->sessionStorage->hasToken()) { |
|
62 | 62 | $value = $this->sessionStorage->getToken(); |
63 | 63 | } else { |
64 | 64 | $value = $this->tokenGenerator->generateToken(); |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @return bool |
97 | 97 | */ |
98 | 98 | public function isTokenValid(CsrfToken $token): bool { |
99 | - if(!$this->sessionStorage->hasToken()) { |
|
99 | + if (!$this->sessionStorage->hasToken()) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | private function hash(string $methodIdentifier, |
59 | 59 | string $userIdentifier): string { |
60 | - return hash('sha512', $methodIdentifier . $userIdentifier); |
|
60 | + return hash('sha512', $methodIdentifier.$userIdentifier); |
|
61 | 61 | } |
62 | 62 | |
63 | 63 | /** |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | } |
72 | 72 | |
73 | 73 | $cachedAttempts = json_decode($cachedAttempts, true); |
74 | - if(\is_array($cachedAttempts)) { |
|
74 | + if (\is_array($cachedAttempts)) { |
|
75 | 75 | return $cachedAttempts; |
76 | 76 | } |
77 | 77 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $currentTime = $this->timeFactory->getTime(); |
92 | 92 | /** @var array $existingAttempts */ |
93 | 93 | foreach ($existingAttempts as $attempt) { |
94 | - if(($attempt + $seconds) > $currentTime) { |
|
94 | + if (($attempt + $seconds) > $currentTime) { |
|
95 | 95 | $count++; |
96 | 96 | } |
97 | 97 | } |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | |
112 | 112 | // Unset all attempts older than $period |
113 | 113 | foreach ($existingAttempts as $key => $attempt) { |
114 | - if(($attempt + $period) < $currentTime) { |
|
114 | + if (($attempt + $period) < $currentTime) { |
|
115 | 115 | unset($existingAttempts[$key]); |
116 | 116 | } |
117 | 117 | } |
118 | 118 | $existingAttempts = array_values($existingAttempts); |
119 | 119 | |
120 | 120 | // Store the new attempt |
121 | - $existingAttempts[] = (string)$currentTime; |
|
121 | + $existingAttempts[] = (string) $currentTime; |
|
122 | 122 | $this->cache->set($identifier, json_encode($existingAttempts)); |
123 | 123 | } |
124 | 124 | } |