Zend Framework come with some built-in adapters. Buit-in adapter include database, LDAP, Http authentication adapter etc. I discussed how to create your own custom Authentication adapter in one of my previous post.
As most of the websites perform authentication against database. So better to discuss database authentication here in this post.
Zend_Auth_Adapter_DbTable provide you an ability to perform authentication against credential stored in database table.
Before writing the code, I would assume that you have done necessary configuration for database adapter in your bootfile. Study me post on Zend_config, if don’t know how to make database configuration.
After making the database configuration, store a reference to it using Zend_Registry.
Once you make the configuration in your bootstrap file. In your controller file, where you want to make authentication write the following code.
$authAdapter= new Zend_Auth_Adapter_DbTable($db);
That’s it you have now defined everything. You will need to pass values posted via form as
And now simply pass this $authAdapter to authenticate() function as
$auth= new Zend_Auth();
Now check if your authentication is valid
$resultRow = $authAdapter->getResultRowObject();
You can place whatever code you want. Create your session and store this resultant row for future use.
Post questions if any.