Skip to content

Commit

Permalink
feat(security): harden security with random_bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
mrflos committed Oct 31, 2024
1 parent e128570 commit 0a8c52d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions includes/services/UserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ protected function generateUserLink($user)
{
// Generate the password recovery key
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
$hashedKey = $passwordHasher->hash($plainKey);
$tripleStore = $this->wiki->services->get(TripleStore::class);
// Erase the previous triples in the trible table
Expand Down Expand Up @@ -254,7 +254,7 @@ public function getUserLink(): string
public function getLastUserLink(User $user): string
{
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
$hashedKey = $passwordHasher->hash($plainKey);
$tripleStore = $this->wiki->services->get(TripleStore::class);
$key = $tripleStore->getOne($user['name'], self::KEY_VOCABULARY, '', '');
Expand Down
2 changes: 1 addition & 1 deletion tools/login/actions/LostPasswordAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ private function sendPasswordRecoveryEmail(User $user)
{
// Generate the password recovery key
$passwordHasher = $this->passwordHasherFactory->getPasswordHasher($user);
$plainKey = $user['name'] . '_' . $user['email'] . random_int(0, 10000) . date('Y-m-d H:i:s');
$plainKey = $user['name'] . '_' . $user['email'] . random_bytes(16) . date('Y-m-d H:i:s');
$hashedKey = $passwordHasher->hash($plainKey);
// Erase the previous triples in the trible table
$this->tripleStore->delete($user['name'], self::KEY_VOCABULARY, null, '', '') ;
Expand Down

0 comments on commit 0a8c52d

Please sign in to comment.