Skip to content

Commit c840f08

Browse files
committedJan 20, 2025
feat(security): harden security with random_bytes
1 parent d0b5d08 commit c840f08

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed
 

‎includes/services/UserManager.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ protected function generateUserLink($user)
212212
{
213213
// Generate the password recovery key
214214
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
215-
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
215+
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
216216
$hashedKey = $passwordHasher->hash($plainKey);
217217
$tripleStore = $this->wiki->services->get(TripleStore::class);
218218
// Erase the previous triples in the trible table
@@ -270,7 +270,7 @@ public function getUserLink(): string
270270
public function getLastUserLink(User $user): string
271271
{
272272
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
273-
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
273+
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
274274
$hashedKey = $passwordHasher->hash($plainKey);
275275
$tripleStore = $this->wiki->services->get(TripleStore::class);
276276
$key = $tripleStore->getOne($user['name'], self::KEY_VOCABULARY, '', '');

‎tools/login/actions/LostPasswordAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ private function sendPasswordRecoveryEmail(User $user)
204204
{
205205
// Generate the password recovery key
206206
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
207-
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
207+
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
208208
$hashedKey = $passwordHasher->hash($plainKey);
209209
// Erase the previous triples in the trible table
210210
$this->tripleStore->delete($user['name'], self::KEY_VOCABULARY, null, '', '') ;

0 commit comments

Comments
 (0)
Failed to load comments.