0

I am new to zend. I am trying to create login form using zend framework. But its creating problem. Below is my function

public function loginAction()
{
    $db = $this->_getParam('db');
    $form = new Application_Form_Login();
    $this->view->form = $form;

    if($this->getRequest()->isPost())
    {
        $formData = $this->getRequest()->getPost();
        if ($form->isValid($formData)) 
        {
        $adapter = new Zend_Auth_Adapter_DbTable(
            $db,
            'users',
            'emailaddress',
            'password',
            'MD5(CONCAT(?, password_salt))'
            );

        $adapter->setIdentity($form->getValue('email'));
        $adapter->setCredential($form->getValue('password'));

        $auth   = Zend_Auth::getInstance();
        $result = $auth->authenticate($adapter);

            if ($result->isValid()) {
                $this->_helper->FlashMessenger('Successful Login');
                $this->_redirect('/');
                return;
            }
        }   
    }
}

its giving error on following line -> $result = $auth->authenticate($adapter);

Error is -> Message: The supplied parameters to Zend_Auth_Adapter_DbTable failed to produce a valid sql statement, please check table and column names for validity.

my table name is 'users' and it has columns(id,firstname,lastname,age,emailaddress,password).

Navdeep
  • 345
  • 5
  • 6
  • 14

1 Answers1

0

You need field named 'password_salt' in your table which will contain salt or just change this

'MD5(CONCAT(?, password_salt))'

to

'MD5(?)'
sas
  • 38
  • 6
  • done by chang code to 'MD5(CONCAT(?, password_salt))' to 'MD5(CONCAT(?))' thanks sas – Navdeep Apr 11 '12 at 08:58
  • hello sas, as you said 'password_salt' field will contain salt. Can you please explain this(salt?) – Navdeep Apr 11 '12 at 09:00
  • 1
    Everything was already told - http://stackoverflow.com/questions/674904/salting-your-password-best-practices . Also you should use SHA1 instead of MD5 (it is safer). And please accept my answer if it helped you. – sas Apr 11 '12 at 09:05