Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c816bff

Browse files
committed
prevent empty username on dbauth register endpoint
1 parent cd78c8c commit c816bff

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
@@ -73,6 +73,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7373
if (!$registerUser) {
7474
return $this->responder->error(ErrorCode::AUTHENTICATION_FAILED, $username);
7575
}
76+
if(strlen(trim($username)) == 0){
77+
return $this->responder->error(ErrorCode::USERNAME_EMPTY, $username);
78+
}
7679
if (strlen($password) < $passwordLength) {
7780
return $this->responder->error(ErrorCode::PASSWORD_TOO_SHORT, $passwordLength);
7881
}

‎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)

AltStyle によって変換されたページ (->オリジナル) /