Skip to content

Fixed the logic of the custom password authenticator #10448

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 14 additions & 20 deletions security/custom_password_authenticator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -68,29 +68,23 @@ the user::
}
}

if ($isPasswordValid) {
$currentHour = date('G');
if ($currentHour < 14 || $currentHour > 16) {
// CAUTION: this message will be returned to the client
// (so don't put any un-trusted messages / error strings here)
throw new CustomUserMessageAuthenticationException(
'You can only log in between 2 and 4!',
array(), // Message Data
412 // HTTP 412 Precondition Failed
);
}

return new UsernamePasswordToken(
$user,
$user->getPassword(),
$providerKey,
$user->getRoles()
$currentHour = date('G');
if ($currentHour < 14 || $currentHour > 16) {
// CAUTION: this message will be returned to the client
// (so don't put any un-trusted messages / error strings here)
throw new CustomUserMessageAuthenticationException(
'You can only log in between 2 and 4!',
array(), // Message Data
412 // HTTP 412 Precondition Failed
);
}

// CAUTION: this message will be returned to the client
// (so don't put any un-trusted messages / error strings here)
throw new CustomUserMessageAuthenticationException('Invalid username or password');
return new UsernamePasswordToken(
$user,
$user->getPassword(),
$providerKey,
$user->getRoles()
);
}

public function supportsToken(TokenInterface $token, $providerKey)
Expand Down