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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:17:23+00:00 2026-06-05T17:17:23+00:00

I cannot login using email in CakePHP 2.1, when i try with username then

  • 0

I cannot login using email in CakePHP 2.1, when i try with username then its working perfectly good.

Below is the code

View : login.ctp

<?php
    echo $this->Form->create();
    echo $this->Form->input('email');
    //echo $this->Form->input('username');
    echo $this->Form->input('password');
    echo $this->Form->end('Login');
?>

Controller : UsersController.php

<?php
    public function login(){
        if ($this->request->is('post')){
            if ($this->Auth->login()){
                $this->redirect($this->Auth->redirect());
            } else {
                $this->Session->setFlash(__('Invalid email and password'));
            }
        }
    }
?>      

Model : User.php

<?php
App::uses('AuthComponent', 'Controller/Component');

class User extends AppModel {
    public function beforeSave(){
        if (isset($this->data[$this->alias]['password'])){
            $this->data[$this->alias]['password'] = AuthComponent::password($this->data[$this->alias]['password']);
        }
        return true;
    }
}
?>  

Database Structure : users table

id Auto_Increment
username
email
password
role

I dont know, why it is not accepting any email id for login but for username its working good.

  • 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-05T17:17:24+00:00Added an answer on June 5, 2026 at 5:17 pm

    Read this section of the CakePHP book.

    Here is the example from that section, you’ll need to configure the form authentication to use a different field for the username.

    public $components = array(
        'Auth' => array(
            'authenticate' => array(
                'Form' => array(
                    'fields' => array('username' => 'email')
                )
            )
        )
    );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Oracle.Web.Security.OracleMembershipProvider MembershipProvider for my ASP.NET application. My login form has username,
I'm using the following code in an ASP.NET page to create a record, then
The facebook login using the Facebook C# SDK was working, but now is not!
I have this login script, but for some reason its not working. I checked
I cannot get the logic for this down correctly. I am using a wizard
i get the error login cannot be resolved or is not a field error
i am tying to login using System.Diagnostics.Process.Start private void button1_Click(object sender, EventArgs e) {
I'm using sendgrid on heroku to send email in production, but would like to
I'm trying to use mysql_real_escape_string() to secure a log in form. Using this code:
I have a code for inserting values in ASP.net using vb. I'm having problem

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.