How to get the number of login attempts in Laravel?
Laravel version 5.7 -
I am currently attempting to grab the number of login attempts. The Laravel's documentation does not provide a guide for this. But I think I am getting closer to finding the answer on my own by backtracking all the methods being called.
Anyhow, my goal is to display the number of 'logins attempted / max login attempt' before the lockout.
In AuthLoginController I can easily get the number of maxAttempts, and even set my preferred number of max attempts:
protected $maxAttempts = 3;
Great. So I create a function to get login attempt details:
public function getCurrentAttempts()
$limiter = $this->limiter();
$login_attempts = array(
// gets the number of current login attempted
'currentAttempts' => $limiter->hit('user'),
// get the number of max attempts allowed
'maxAttempts' => $this->maxAttempts(),
// return 1 or 0 if current login attempts reached max attempts
'locked' => $this->limiter()->tooManyAttempts('user', $this->maxAttempts())
);
return view('auth.login')->withLoginAttempts(
$login_attempts
);
Please note:
$this->limiter()->hit(key)
<<< expects a key. I really don't know what kind of key it is expecting. Help anyone? I typed 'user', and for some reason is sending me back the correct number of attempts. But is this correct? Is that the 'key' that $limiter->hit()
is expecting? Doesn't the 'key' has something to do with Request?
Other things to note:
Nicely enough, from the LoginController I can easily get the $maxAttempts value by simply $this->maxAttempts()
, that's really nice. But what about the number of current login attempts? Wouldn't it be ideal to have it in the same place? That's what I am trying to get.
laravel-5.7
add a comment |
Laravel version 5.7 -
I am currently attempting to grab the number of login attempts. The Laravel's documentation does not provide a guide for this. But I think I am getting closer to finding the answer on my own by backtracking all the methods being called.
Anyhow, my goal is to display the number of 'logins attempted / max login attempt' before the lockout.
In AuthLoginController I can easily get the number of maxAttempts, and even set my preferred number of max attempts:
protected $maxAttempts = 3;
Great. So I create a function to get login attempt details:
public function getCurrentAttempts()
$limiter = $this->limiter();
$login_attempts = array(
// gets the number of current login attempted
'currentAttempts' => $limiter->hit('user'),
// get the number of max attempts allowed
'maxAttempts' => $this->maxAttempts(),
// return 1 or 0 if current login attempts reached max attempts
'locked' => $this->limiter()->tooManyAttempts('user', $this->maxAttempts())
);
return view('auth.login')->withLoginAttempts(
$login_attempts
);
Please note:
$this->limiter()->hit(key)
<<< expects a key. I really don't know what kind of key it is expecting. Help anyone? I typed 'user', and for some reason is sending me back the correct number of attempts. But is this correct? Is that the 'key' that $limiter->hit()
is expecting? Doesn't the 'key' has something to do with Request?
Other things to note:
Nicely enough, from the LoginController I can easily get the $maxAttempts value by simply $this->maxAttempts()
, that's really nice. But what about the number of current login attempts? Wouldn't it be ideal to have it in the same place? That's what I am trying to get.
laravel-5.7
add a comment |
Laravel version 5.7 -
I am currently attempting to grab the number of login attempts. The Laravel's documentation does not provide a guide for this. But I think I am getting closer to finding the answer on my own by backtracking all the methods being called.
Anyhow, my goal is to display the number of 'logins attempted / max login attempt' before the lockout.
In AuthLoginController I can easily get the number of maxAttempts, and even set my preferred number of max attempts:
protected $maxAttempts = 3;
Great. So I create a function to get login attempt details:
public function getCurrentAttempts()
$limiter = $this->limiter();
$login_attempts = array(
// gets the number of current login attempted
'currentAttempts' => $limiter->hit('user'),
// get the number of max attempts allowed
'maxAttempts' => $this->maxAttempts(),
// return 1 or 0 if current login attempts reached max attempts
'locked' => $this->limiter()->tooManyAttempts('user', $this->maxAttempts())
);
return view('auth.login')->withLoginAttempts(
$login_attempts
);
Please note:
$this->limiter()->hit(key)
<<< expects a key. I really don't know what kind of key it is expecting. Help anyone? I typed 'user', and for some reason is sending me back the correct number of attempts. But is this correct? Is that the 'key' that $limiter->hit()
is expecting? Doesn't the 'key' has something to do with Request?
Other things to note:
Nicely enough, from the LoginController I can easily get the $maxAttempts value by simply $this->maxAttempts()
, that's really nice. But what about the number of current login attempts? Wouldn't it be ideal to have it in the same place? That's what I am trying to get.
laravel-5.7
Laravel version 5.7 -
I am currently attempting to grab the number of login attempts. The Laravel's documentation does not provide a guide for this. But I think I am getting closer to finding the answer on my own by backtracking all the methods being called.
Anyhow, my goal is to display the number of 'logins attempted / max login attempt' before the lockout.
In AuthLoginController I can easily get the number of maxAttempts, and even set my preferred number of max attempts:
protected $maxAttempts = 3;
Great. So I create a function to get login attempt details:
public function getCurrentAttempts()
$limiter = $this->limiter();
$login_attempts = array(
// gets the number of current login attempted
'currentAttempts' => $limiter->hit('user'),
// get the number of max attempts allowed
'maxAttempts' => $this->maxAttempts(),
// return 1 or 0 if current login attempts reached max attempts
'locked' => $this->limiter()->tooManyAttempts('user', $this->maxAttempts())
);
return view('auth.login')->withLoginAttempts(
$login_attempts
);
Please note:
$this->limiter()->hit(key)
<<< expects a key. I really don't know what kind of key it is expecting. Help anyone? I typed 'user', and for some reason is sending me back the correct number of attempts. But is this correct? Is that the 'key' that $limiter->hit()
is expecting? Doesn't the 'key' has something to do with Request?
Other things to note:
Nicely enough, from the LoginController I can easily get the $maxAttempts value by simply $this->maxAttempts()
, that's really nice. But what about the number of current login attempts? Wouldn't it be ideal to have it in the same place? That's what I am trying to get.
laravel-5.7
laravel-5.7
asked Nov 13 '18 at 0:53
Michael BerriosMichael Berrios
314
314
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
After reading the Laravel docs several times, I began to try various classes already built in within the framework that allowed me to achieve my goal (getting the current number of login attempts)
In the LoginController we must use IlluminateHttpRequest;
and then by method injection, the Request $request
can be captured in the method.
I was then able to get the 'throttleKey', which is the key that I needed like so:
In the LoginController's method body, $this->limiter()->hit($this->throttleKey($request));
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272229%2fhow-to-get-the-number-of-login-attempts-in-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
After reading the Laravel docs several times, I began to try various classes already built in within the framework that allowed me to achieve my goal (getting the current number of login attempts)
In the LoginController we must use IlluminateHttpRequest;
and then by method injection, the Request $request
can be captured in the method.
I was then able to get the 'throttleKey', which is the key that I needed like so:
In the LoginController's method body, $this->limiter()->hit($this->throttleKey($request));
add a comment |
After reading the Laravel docs several times, I began to try various classes already built in within the framework that allowed me to achieve my goal (getting the current number of login attempts)
In the LoginController we must use IlluminateHttpRequest;
and then by method injection, the Request $request
can be captured in the method.
I was then able to get the 'throttleKey', which is the key that I needed like so:
In the LoginController's method body, $this->limiter()->hit($this->throttleKey($request));
add a comment |
After reading the Laravel docs several times, I began to try various classes already built in within the framework that allowed me to achieve my goal (getting the current number of login attempts)
In the LoginController we must use IlluminateHttpRequest;
and then by method injection, the Request $request
can be captured in the method.
I was then able to get the 'throttleKey', which is the key that I needed like so:
In the LoginController's method body, $this->limiter()->hit($this->throttleKey($request));
After reading the Laravel docs several times, I began to try various classes already built in within the framework that allowed me to achieve my goal (getting the current number of login attempts)
In the LoginController we must use IlluminateHttpRequest;
and then by method injection, the Request $request
can be captured in the method.
I was then able to get the 'throttleKey', which is the key that I needed like so:
In the LoginController's method body, $this->limiter()->hit($this->throttleKey($request));
answered Nov 17 '18 at 21:12
Michael BerriosMichael Berrios
314
314
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53272229%2fhow-to-get-the-number-of-login-attempts-in-laravel%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown