Skip to content

Commit 7cb3bf7

Browse files
authored
Merge pull request #13 from HuongNV13/fixHashPassword
Fix the hashPassword in General Trait
2 parents ae7ad3d + 38b992e commit 7cb3bf7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

application/src/Controller/BackOfficeController.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ public function backOfficeCreateAdmin(string $serverID, Request $request) : Json
6969
// 2. Generates and returns token pattern.
7070
$newpassword = $this->hashPassword('password', null, true);
7171

72+
if (!$newpassword['token']) {
73+
return new JsonResponse((object) [
74+
'errcode' => 'M_INVALID_TOKEN',
75+
'error' => 'Cannot hash the token.'
76+
], 400);
77+
}
78+
7279
// New user, or existing user without any associated Tokens.
7380
$password = new Password();
7481
$password->setPassword($newpassword['token']);

application/src/Traits/GeneralTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ private function hashPassword(string $extra = null, string $dashedPattern = null
7373
$createdTokenPattern = [];
7474
$dashedPattern = $dashedPattern ? explode(',', $dashedPattern) : [];
7575
for ($i = 0; $i < strlen($string); $i++) {
76-
$randomDashedPosition = count($dashedPattern) > 0 ? (int)$dashedPattern[$i] : (int)rand(1, 10);
76+
$randomDashedPosition = count($dashedPattern) > 0 ? (int)$dashedPattern[$i] : rand(4, 10);
7777
if (count($dashedPattern) > 0) {
7878
$previousPosition = (int)($previousPosition + $randomDashedPosition);
7979
$token = substr_replace($token ?? $string, '-', $previousPosition, 1);

0 commit comments

Comments
 (0)