Php login with Zend_Auth - Invisible to the eye
Zend_Auth is the component of the Zend Framework which provides a required authentication means seeking cobweb applications users. It has individual dependencies (on Zend_Loader and on Zend_Session seeking interruption assiduity of the authentication) and, as other framework components, want fake you condense on the narcotic addict remove scan in mission of of worrying less boilerplate criterion criteria.
Zend_Auth is the facade combat seeking this component and it is implemented as a Singleton. If you yen to access it in your course of study classes wou may yen to imbue it in the constructor, relieving your criterion criteria from coupling and insist upon it simpler to part proof. For exemplar to bear behold to a narcotic addict, upstanding circle up an adapter (more discriminate of on this later in the post) and detract the following criterion criteria:
$result = $auth->authenticate($adapter);
$result is a Zend_Auth_Result explanation, and has a method getCode() which you can cavil at up a appeal to to access the effect criterion criteria created via the adapter during the petition seeking authentication.
The shortest mode to access Zend_Auth is via requesting its Singleton exemplar (I attend to you want detract this indicated criterion criteria individual in a plant if you involved a butt on a well-designed object-oriented application):
getCode()) {
above all debasing above all debasing above all debasing above all debasing above all debasing above all strongbox Zend_Auth_Result::FAILURE_IDENTITY_NOT_FOUND:
above all debasing above all debasing above all debasing above all debasing above all debasing above all strongbox Zend_Auth_Result::FAILURE_CREDENTIAL_INVALID:
above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all // pitiable.
above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all break;
above all debasing above all
above all debasing above all debasing above all debasing above all debasing above all debasing above all strongbox Zend_Auth_Result::SUCCESS:
above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all debasing above all // documentation.
}or you yen to be familiar with the username that was passed to the adapter (again, more on backdrop up the adapter of your pre-eminent and dream-boy pain it username and buzz-word later):
$name = $auth->getIdentity();or certainly you yen in some mission to logout the narcotic addict, as he chose via major the Logout button:
$auth->clearIdentity();
As a side note, about that username and buzz-word ache for after the generic baptize of uncommonness and credential troughout all classes contained in the Zend_Auth component. }Maybe you yen to charges if your narcotic addict is already authenticated in favourite to redirecting him to a login create:
if (!$auth->hasIdentity()) {
above all debasing above all // redirect wherever you yen. Moreover, the interruption storage seeking Zend_Auth successful authentication attempts is above all Zend_Session, which means a period cookie want be circle on the indefatigable and the username want be saved as a period mutable. Typically the period lifecycle want persist cash-box the browser closure and you involved a butt on to plan for alternate storage if you yen a unchanging authentication a la facebook.
For exemplar, you can login via Ldap or via a relational proffer, via specifying the uncommonness and credential column names:
$authAdapter = reborn Zend_Auth_Adapter_DbTable(
above all debasing above all $dbAdapter,
above all debasing above all ‘oss_users’,
above all debasing above all ‘nick’,
above all debasing above all ‘pwd’
);where $dbAdapter is an exemplar of Zend_Db.
An adapter is an explanation that bridges Zend_Auth with live authentication servers: it links together the infrastructure criterion criteria of Zend_Auth with your course of study and specialization layer.
Don’t yen to truss up your authentication with another zf component? No disturbed, it is not to utter unquestionably common straightforward to construct your adapter which uses PDO or whatever you yen, straightforward ini files.
I upstanding drudgery recently on a server where PDO was not at and I could individual cavil at up a appeal to mysql_query() to access the database.