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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T21:35:04+00:00 2026-06-14T21:35:04+00:00

i have problem in login form $this->Auth->login() always returns false. i am using different

  • 0

i have problem in login form $this->Auth->login() always returns false. i am using different table name for user account. the below is my code

HgAdminscontroller.php

    <?php
    // app/Controller/UsersController.php
    class HgAdminsController extends AppController 
{
    public function beforeFilter() 
    {
        parent::beforeFilter();
        //$this->Auth->allow('add', 'logout');
    }
    public function index() {
        $this->HgAdmin->recursive = 0;
        $this->set('users', $this->paginate());
    }
    /*
public function add() {
if ($this->request->is('post')) {
$this->HgAdmin->create();
if ($this->HgAdmin->save($this->request->data)) {
$this->Session->setFlash(__('The user has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The user could not be saved. Please, try again.'));
}
}
}*/
    public function login() {

    if ($this->request->is('post')) {
    echo AuthComponent::password($this->data['password']);
    debug($this->data);
        if ($this->Auth->login()) {
        $this->redirect($this->Auth->redirect());
        } else {
        $this->Session->setFlash(__('Invalid username or password, try again'));
        }
    }
    }
    public function logout() {
        $this->redirect($this->Auth->logout());
    }
}
?>

appController.php
App::uses('Controller', 'Controller');

/**
 * Application Controller
 *
 * Add your application-wide methods in the class below, your controllers
 * will inherit them.
 *
 * @package       app.Controller
 * @link http://book.cakephp.org/2.0/en/controllers.html#the-app-controller
 */
    class AppController extends Controller {
    public $components = array(
        'Session',
        'Auth' => array(
        'loginRedirect' => array('controller' => 'posts', 'action' => 'index'),
        'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
        )
    );
    public function beforeFilter() {
        $this->Auth->allow('index', 'view');
//      Security::setHash('md5');
        $this->Auth->userModel = 'hg_admins';
        $this->Auth->loginAction = array( 'controller' => 'HgAdmins', 'action' => 'login' );
    }
//...
}

HgAdmin.php //model
<?php 
class HgAdmin extends AppModel {
    var $name= "hg_admin";
    public $validate = array(
        'username' => array(
        'required' => array(
        'rule' => array('notEmpty'),
        'message' => 'A username is required'
        )
    ),
        'password' => array(
        'required' => array(
        'rule' => array('notEmpty'),
        'message' => 'A password is required'
        )
    )
    );

?>

Login view

<h2>Login Here</h2>
<?php echo $this->Session->flash('auth'); 
echo $this->form->create('HgAdmin');
echo $this->Form->input("username");
echo $this->Form->input("password");
echo $this->form->end(__("Login"));
?>

i have checked the database password value is same as comming from AuthComponent::password($this->data[‘password’]); so dont know why it is fialing. if i use add function of cakephp to add user the user is added with the same password but not able to login with that.

  • 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-14T21:35:05+00:00Added an answer on June 14, 2026 at 9:35 pm
    public $components = array(
     'Auth' => array(
        'loginAction' => array(
            'controller' => 'writers',
            'action' => 'login'
    
        ),
        'loginRedirect' => array(
            'controller' => 'home',
            'action' => 'index'
        ),
        'logoutRedirect' =>array (
            'controller' => 'home',
            'action' => 'index'
        ),
         'authError' => 'You have to login to access this page',
        'authenticate' => array(
            'Form' => array(
                'userModel' =>'Writer',
                'fields' => array('username' => 'email')
            )
        ),
        'scope' =>array('User.status' => '1'),
        'authorize' => array('Controller')
    ),
      'Session',
    );
    

    You have to use the name of the Model on which you want to apply authentication i.e i ahve used Writer for my table writers in db.Check changing that!

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

Sidebar

Related Questions

I have implemented a login form using JSF and PrimeFaces. I used this example
I have the follow problem. This is the situation i've got when user login
The problem I am encountering is that for my login form I have to
I have a simple login form, username and password. Basically, When a user is
I ran into a problem when using Mechanize to submit a login form. For
I have a problem in lightbox. This is the link when i clicked login
I am modifying my login/registration form via login.phtml and have a problem with the
I'm currently creating a Login form and have this code: string connectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
I have a simple html login form, deployed on Xcode using phonegap framework. When
Im using Django 1.2.3. I have login functionality in my site using django.contrib.auth.views.login .

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.