I’m trying to make my custom filter work…
I have the following code in my AuthController:
<?php
public function loginAction()
{
// Get db var
$db = $this->_getParam('db');
// Load loginform
$loginForm = new Application_Form_Auth_Login();
// Form posted?
if ($loginForm->isValid($_POST))
{
// Setup adapter
$adapter = new Zend_Auth_Adapter_DbTable(
$db,
'users',
'username',
'password'
);
// Set identity and credential
$adapter->setIdentity($loginForm->getValue('username'));
$adapter->setCredential($loginForm->getValue('password'));
// Setup Zend_Auth and try to authenticate the user
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($adapter);
// If authentication succeed
if ($result->isValid())
{
$this->_helper->FlashMessenger('Inloggen geslaagd');
$this->_redirect('/');
return;
}
else
{
$this->_helper->FlashMessenger('Inloggen geslaagd');
}
}
$this->view->loginForm = $loginForm;
}
?>
The code of the form is:
<?php
class Application_Form_Auth_Login extends Zend_Form
{
/**
* Default_Form_Auth_Login::init()
*
* Form which authenticates guests
*
* @return void
*/
public function init()
{
$this->setMethod('post');
$this->addElement('text', 'username', array(
'label' => 'Gebruikersnaam:',
'required' => true,
'filters' => array('StringTrim'),
));
$this->addElement('password', 'password', array(
'label' => 'Wachtwoord:',
'required' => true,
'filters' => array('Pcw_Filter_Hash')
));
$this->addElement('hash', 'formToken', array(
'salt' => 'unique'
));
$this->addElement('submit', 'submit', array(
'ignore' => true,
'label' => 'Inloggen',
));
}
}
The code of my custom filter is:
<?php
class Pcw_Filter_Hash implements Zend_Filter_interface
{
/**
* HashFilter::filter()
*
* @param string $value
* @return
*/
public function filter($value)
{
return hash('sha512', $value);
}
}
When using it this way I keep getting this message:
Message: Plugin by name ‘Pcw_Filter_Hash’ was not found in the registry; used paths: Zend_Filter_: Zend/Filter/
I have found documentation about setting namespaces and adding paths but I can’t get anything to work…
Does anyone has a working solution for my problem? This will be highly apprectiated!
Thanks in advance!
I would rather rewrite you form elements like this one :
but I am not sure this might work :
and you should double check that
Pcwis defined inapplication.iniI hope your problem get solved soon 🙂