Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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