Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1025631
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:57:25+00:00 2026-05-16T11:57:25+00:00

I am using the core Auth component. I have created a user login that

  • 0

I am using the core Auth component. I have created a user login that manages all of the permissions. The way I am implementing the login monitoring is by checking for $this->Auth->user() in the app_controller. Each time the app_controller cycles the beforeFilter() function and !$this->Auth->user(), it will increment the Captcha.LoginAttempts session variable. When Captcha.LoginAttempts is > 3, I want it to redirect to the Captchas controller, displaying a captcha screen requiring the user to confirm they are a human. (Similar to how stackoverflow does it).

The issue I am having is if I am using an element somewhere or referencing something within the cake framework on the page, it will hit the redirect and cause an endless circular redirect for every accessing element/component being called external to the actual controller/action. Is there a better way to implement this?

Here is the actual code I have been messing with. But it basically sucks (IMO):

// this is in the app_controller beforeFilter() method.

if($this->Auth->user()) {
            $this->Session->delete('Captcha');
        } else {
            $this->Session->write('Captcha.LoginAttempts', $this->Session->read('Captcha.LoginAttempts') + 1);
            if ($this->Session->read('Captcha.LoginAttempts') > 3) {
                if (!$this->Session->read('Captcha.controller')) {
                    $this->Session->write('Captcha.controller', $this->params['controller']);
                    $this->Session->write('Captcha.action', $this->params['action']);
                }
                if ($this->Session->read('Captcha.fail') !== 'true') { // avoid circular reference redirects
                    $this->Session->write('Captcha.fail', 'true');
                    $this->redirect(array('controller' => 'captchas', 'action' => 'index'));
                }
            }
        }

You can see how I try to avoid the circular reference. But then the user could just go to the login page and since the Captcha.fail session variable is already set, it will ignore the redirect. There must be a more elegant way to implement this. Anyone?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:57:25+00:00Added an answer on May 16, 2026 at 11:57 am

    Normally, I would just try to answer the way you are trying to do it, but since you asked for any better ideas, what I would do is have the Captcha actually on the login page and use the AuthComponents builtin methods and properties like loginRedirect, autoRedirect, and allow(). Then, just turn the captcha on/off based on the Captchas.loginAttempts variable.

    For your current method, I don’t think you’re going to get an elegant way of doing this. However, you might be able to change the properties of the AuthComponent to get what you want. You could change loginRedirect and loginAction so that /captchas/index is the new login form, then on successful captcha, set loginAction back to /users/login or whatever. This way, if someone were to attempt to hit /users/login directly without doing the captcha, then the AuthComponent logic would kick in and redirect to /captchas/index.

    Here are some relevant manual pages:

    • http://book.cakephp.org/view/392/loginRedirect
    • http://book.cakephp.org/view/382/allow
    • http://book.cakephp.org/view/395/autoRedirect
    • http://book.cakephp.org/view/391/loginAction

    Hope this helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a auth-redirect module that is in the beginning of all my page
I am using the auth component straight out the box. When a user enters
Using core graphics , I am trying to draw a line, in that when
Using Core Data, I have a fetch request to fetch the minimum of a
I am writing a web application and have just implemented that a user can
Using core data I'd like to fetch some data. My model uses some abstract
I am using core data and set up a one to many relationship for
i am using core data in my application. i am getting this error when
I am using core location framework inside my app and sending updated location to
I am using core location framework inside my app.The didUpdateToLocation method is called two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.