Prev | Current Page 177 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

com>
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
The authenticate() function is used to perform the actual authentication as shown in listing 6.2.
Listing 6.3 Authentication with Zend_Auth_Adapter_Http
$result = $authAdapter->authenticate(); #1
if (!$result->isValid()) {
// Failed to validate. The response contains the correct HTTP
// headers for the browser to ask for a username/password.
$response->appendBody('Sorry, you are not authorised');
} else {
// Successfully validated.
$identity = $result->getIdentity(); #2
$username = $identity['username'];
$response->appendBody('Welcome, '.$username);
}
(annotation) <#1. Authenticate supplied username and password.>
(annotation) <#2. Retrieve the username and realm from the result.>
When authenticate() is called, it looks for the username and password HTTP headers. If they are not their,
then the validation has failed, and it will set the ???WWW-Authenticate??? header in the response object. This will
result in the browser displaying a dialog box requesting a username and password. Upon successful validation,
the username of the person who has just logged in can be retrieved using the getIdentity() function which
returns a (#2).


Pages:
165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
Wczasy nad morzem kasyno kino azjatyckie bwin out of home advertising