Skip to content

Commit

Permalink
Merge pull request #13 from HuongNV13/fixHashPassword
Browse files Browse the repository at this point in the history
Fix the hashPassword in General Trait
  • Loading branch information
lameze authored Sep 5, 2024
2 parents ae7ad3d + 38b992e commit 7cb3bf7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 7 additions & 0 deletions application/src/Controller/BackOfficeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
// 2. Generates and returns token pattern.
$newpassword = $this->hashPassword('password', null, true);

if (!$newpassword['token']) {
return new JsonResponse((object) [
'errcode' => 'M_INVALID_TOKEN',
'error' => 'Cannot hash the token.'
], 400);
}

// New user, or existing user without any associated Tokens.
$password = new Password();
$password->setPassword($newpassword['token']);
Expand Down
2 changes: 1 addition & 1 deletion application/src/Traits/GeneralTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private function hashPassword(string $extra = null, string $dashedPattern = null
$createdTokenPattern = [];
$dashedPattern = $dashedPattern ? explode(',', $dashedPattern) : [];
for ($i = 0; $i < strlen($string); $i++) {
$randomDashedPosition = count($dashedPattern) > 0 ? (int)$dashedPattern[$i] : (int)rand(1, 10);
$randomDashedPosition = count($dashedPattern) > 0 ? (int)$dashedPattern[$i] : rand(4, 10);
if (count($dashedPattern) > 0) {
$previousPosition = (int)($previousPosition + $randomDashedPosition);
$token = substr_replace($token ?? $string, '-', $previousPosition, 1);
Expand Down

0 comments on commit 7cb3bf7

Please sign in to comment.