|
|||
|
Hi everybody,
I have a big question for you: in PHP native in order to check an user authentication we were used to perform an action like this: if($_SESSION["auth"]) echo "authenticated"; else exit(); but using ZF in order to check the privilege, we have to call Zend_Auth::getInstance() that creates a session cookie, even if the vistor isn't authenticated, haven't we? After that we have a cookie for session! Please let me know if I am right and or show me a workaround. thank you cheers Fabrizio |
|
||||
|
yes and no.
Zend_Auth::getInstance() actually creates a session name space. I believe the default is 'Default'. Once a user authenticates that namespace recieves an identity. So to check if a user is authenticated you do the following: Code:
//get an instance of the auth object which is bound to the session namespace 'Default'
$auth = Zend_Auth::getInstance()
if ($auth->hasIdentity()) {
echo "Authenticated!";
} else {
echo "Not Authenticated!";
}
What I prefer is to actually create my own session namespace in my bootstrap: Code:
$session = new Zend_Session_Namespace('Default');
Zend_Registry::set('session', $session);
Code:
$auth = Zend_Auth::getInstance()
$auth->setStorage(new Zend_Auth_Storage_Session('Default'));
Last edited by Elemental : 08-14-2007 at 09:09 PM. |
|
|||
|
I get your point,
but actually my question was realted to the security issues that an instance of auth session could bring to your application. In my opinion (after have checked the source code of Zend_Auth::getInstance()), in order to check if a session exists ZF creates it executing a call to new Zend_Session_Namespace('Auth')! So, if it didn't exist before, after checking it will exist, and a cookie auth will be created! It will be empty but in facts it will be created! Someone maliciuos user that tries to hack our application bypassing the login usin some tecnique of coockie poisoning could find an auth cookie instancieted, even if our purpose was just to check the privileges not to gain them! Addinctionally I think your idea to set authenticated data in the same session coockie 'Defualt' could be a wrong idea, because of the fact I've just explained. |
![]() |
| Thread Tools | |
| Display Modes | |
|
|