function RestAuthenticationController::getLoginFloodIdentifier
Same name and namespace in other branches
- 11.x core/modules/rest/src/Controller/RestAuthenticationController.php \Drupal\rest\Controller\RestAuthenticationController::getLoginFloodIdentifier()
Gets the login identifier for user login flood control.
Parameters
\Symfony\Component\HttpFoundation\Request $request: The current request.
string $username: The username supplied in login credentials.
Return value
string The login identifier or if the user does not exist an empty string.
2 calls to RestAuthenticationController::getLoginFloodIdentifier()
- RestAuthenticationController::floodControl in core/
modules/ rest/ src/ Controller/ RestAuthenticationController.php - Enforces flood control for the current login request.
- RestAuthenticationController::login in core/
modules/ rest/ src/ Controller/ RestAuthenticationController.php - Logs in a user.
File
-
core/
modules/ rest/ src/ Controller/ RestAuthenticationController.php, line 321
Class
- RestAuthenticationController
- Provides controllers for login, login status and logout via HTTP requests.
Namespace
Drupal\rest\ControllerCode
protected function getLoginFloodIdentifier(Request $request, string $username) : string {
$flood_config = $this->config('user.flood');
$accounts = $this->entityTypeManager
->getStorage('user')
->loadByProperties([
'name' => $username,
'status' => 1,
]);
if ($account = reset($accounts)) {
if ($flood_config->get('uid_only')) {
// Register flood events based on the uid only, so they apply for any
// IP address. This is the most secure option.
$identifier = $account->id();
}
else {
// The default identifier is a combination of uid and IP address. This
// is less secure but more resistant to denial-of-service attacks that
// could lock out all users with public user names.
$identifier = $account->id() . '-' . $request->getClientIp();
}
return $identifier;
}
return '';
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.