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 8936177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:09:37+00:00 2026-06-15T10:09:37+00:00

The default login process requires e-mail, not username. I’ve added this to AppController.php on

  • 0

The default login process requires e-mail, not username.

I’ve added this to AppController.php on beforeFilter(), which is also mentioned on CakePHP’s Docs Authentication:

$this->Auth->fields = array(
    'username' => 'username',
    'password' => 'password'
);

But somehow it does not allow users to login with their usernames. Any ideas on how I can change that?

AppController

App::uses('Controller', 'Controller');
class AppController extends Controller {
var $components = array(
    'Session',
    'RequestHandler',
    'Security'
);
var $helpers = array('Form', 'Html', 'Session', 'Js');

public function beforeFilter() {
    $this->Auth->authorize = 'Controller';
    $this->Auth->fields = array('username' => 'username', 'password' => 'password');
    $this->Auth->loginAction = array('plugin' => 'users', 'controller' => 'users', 'action' => 'login', 'admin' => false);
    $this->Auth->loginRedirect = '/';
    $this->Auth->logoutRedirect = '/';
    $this->Auth->authError = __('Sorry, but you need to login to access this location.', true);
    $this->Auth->loginError = __('Invalid e-mail / password combination.  Please try again', true);
    $this->Auth->autoRedirect = true;
    $this->Auth->userModel = 'User';
    $this->Auth->userScope = array('User.active' => 1);  
    if ($this->Auth->user()) {
        $this->set('userData', $this->Auth->user());
        $this->set('isAuthorized', ($this->Auth->user('id') != ''));
    }
}

/View/Users/login.ctp

This is the same as the default login.ctp found in the plugin’s folder. I just changed the field email to username.

Now, here is something interesting. Regardless the code I put in this file, CakePHP pulls the content from the plugin login view, the view I created is ignored.

Debugging

When calling the debugger:

Debugger::dump($this->Auth);

It shows all the values that I set. But it still does not accept the username. I can still login with email, so it is not that I am inserting the wrong credentials. It is just that it is waiting for email/password, not username/password.

  • 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-06-15T10:09:39+00:00Added an answer on June 15, 2026 at 10:09 am

    Try configuring it on the $components in AppController:

    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'username')
                )
            )            
        )
    }
    

    I had the problem on the inverse way, I wanted to validate users with their mail, and not username, and using the above configuration with ‘username’ => ’email’ worked for me.

    EDIT:

    public $components = array(
        'Acl',
        'Auth' => array(
            'authorize' => array(
                'Actions' => array('actionPath' => 'controllers')
            ),
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )            
        ),
        'Session'
    );
    
    public function beforeFilter() {
        //User settings
        $this->activeUserId = $this->Auth->user;
        $this->set('activeuserphoto', $this->Auth->user('photo'));
        $this->set('activeusername', $this->Auth->user('username'));
    
        //Configure AuthComponent
        $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
        $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
        $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'dashboard');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By default, Membership API uses a separate username field to login users. I would
What is the *nix command to view a user's default login shell? I can
I implemented Forms authentication by creating Default.aspx and custom login page named login.aspx .
Single Application Page Asp.net MVC 4 temlplate uses default database to check Login and
I'm using Spring Security 3 and my ApplicationContext-Security.xml specifies <form-login login-page=/genesis default-target-url=/diagnostics/start-diagnostics authentication-failure-url=/genesis?authfailed=true authentication-success-handler-ref=customTargetUrlResolver/>
By default, the ordered list looks like this: There are some spacing on the
I'm saving an user's default language in his user profile and on login I
I have a login page where user enters Username(textbox), Password(textbox), and location(dropdownlist) then login.
I have an admin webapp.one have to login before perfoming any action.Now the /default/index/index
I am in process of making my bootstrap.php file more organized, but after I

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.