Skip to content

Commit 2c2e30c

Browse files
authored
Merge pull request #901 from maheini/prevent_empty_username
prevent empty username on dbauth register endpoint
2 parents fa7e60e + c816bff commit 2c2e30c

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

src/Tqdev/PhpCrudApi/Middleware/DbAuthMiddleware.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7777
if (!$registerUser) {
7878
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
7979
}
80+
if(strlen(trim($username)) == 0){
81+
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
82+
}
8083
if (strlen($password) < $passwordLength) {
8184
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
8285
}

src/Tqdev/PhpCrudApi/Record/ErrorCode.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ class ErrorCode
3333
const PAGINATION_FORBIDDEN = 1019;
3434
const USER_ALREADY_EXIST = 1020;
3535
const PASSWORD_TOO_SHORT = 1021;
36+
const USERNAME_EMPTY = 1022;
3637

3738
private $values = [
3839
0000 => ["Success", ResponseFactory::OK],
@@ -58,6 +59,7 @@ class ErrorCode
5859
1019 => ["Pagination forbidden", ResponseFactory::FORBIDDEN],
5960
1020 => ["User '%s' already exists", ResponseFactory::CONFLICT],
6061
1021 => ["Password too short (<%d characters)", ResponseFactory::UNPROCESSABLE_ENTITY],
62+
1022 => ["Username is empty or only whitespaces", ResponseFactory::UNPROCESSABLE_ENTITY],
6163
9999 => ["%s", ResponseFactory::INTERNAL_SERVER_ERROR],
6264
];
6365

0 commit comments

Comments
 (0)