0
votes

I'm using Employees as the model to handle usernames and password. It does redirect to the correct Controller and action but $this->Auth->login() doesn't seem to be working correctly. Does anyone see a problem?

EmployeesController

public function index() {
        //Set layout to login
        $this->layout = 'login';

        //Set salt
        //Convert user password to md5
        $this->request->data['password'] = md5($this->request->data['password'].$salt); 

         //if already logged-in, redirect
        if($this->Session->check('Auth.User')){
            $this->redirect(array('action' => 'index'));      
        }
        if ($this->request->is('post')) {
                echo "here";
            if ($this->Auth->login()) {
                echo $this->Auth->user('username');
                $this->redirect($this->Auth->redirectUrl());
            } else {
                echo "Invlaid Username";
            }
        } 

    }

AppController

public $components = array(
        'Session',
        'Auth' => array(
            'loginAction' => array(
                'controller' => 'Employees',
                'action' => 'index',
            ),
            'authenticate' => array(
                'all' => array('userModel' => 'Employee'),
                'Form' => array(
                    'userModel' => 'Employee',
                    'fields' => array(
                        'username' => 'employee_id',
                        'password' => 'password',
                    )
                )
            )   
        ),
    );

print_r of $this->request->data

Array ( [Employee] => Array ( [username] => tmoorlag [password] => a8c407a6218250985ccd24ff9ec6 ) )

1

1 Answers

1
votes

It should be

$this->request->data['Employee']['password']  = md5($this->request->data['Employee']['password'].$salt);