Skip to content

Commit a60881c

Browse files
committed
Add new hashPassword function
1 parent 41a7561 commit a60881c

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

index.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414

1515
require __DIR__ . '/src/helpers/headers.inc.php';
16+
require __DIR__ . '/src/helpers/misc.inc.php';
1617
require __DIR__ . '/src/config/config.inc.php';
1718
require __DIR__ . '/src/config/database.inc.php'; // TODO Could find sth cleaner
1819
require __DIR__ . '/src/Route/routes.php';

src/Service/User.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public function create(mixed $data): array|object
2828
->setLastName($data->last)
2929
->setEmail($data->email)
3030
->setPhone($data->phone)
31-
->setPassword(password_hash($data->password, PASSWORD_ARGON2I))
31+
->setPassword(hashPassword($data->password))
3232
->setCreationDate(date(self::DATE_TIME_FORMAT));
3333

3434
$email = $userEntity->getEmail();

src/helpers/misc.inc.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?php
22
// miscellaneous file (MISC)
33

4+
const PASSWORD_COST_FACTOR = 12;
5+
46
function response($data): void {
57
echo json_encode($data);
68
}
9+
10+
function hashPassword(string $password): false|null|string {
11+
return password_hash($password, PASSWORD_ARGON2I, ['cost' => PASSWORD_COST_FACTOR]);
12+
}

0 commit comments

Comments
 (0)