"La sicurezza non è un prodotto ma un processo" Bruce Schneier

(English) Refactoring the ZF Secure Login example with Zend_Application

Posted: ottobre 22nd, 2009 | Author: | Filed under: Zend Framework | Tags: , , , , | 17 Comments »

Ci spiace, ma questo articolo è disponibile soltanto in English.


17 Comments on “(English) Refactoring the ZF Secure Login example with Zend_Application”

  1. 1 fabio said on ottobre 26th, 2009:

    I am new to zend framework, how do I create a bootstrap to put in index.php in the root folder?

  2. 2 Enrico Zimuel said on ottobre 26th, 2009:

    You can use the Zend_Application class and run the bootstrap method of it.
    For instance:
    $application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . ‘/configs/application.ini’
    );
    $application->bootstrap()->run();
    where application.ini contains all the configurations of the application. You can see the source of my example.

  3. 3 John Hamson said on novembre 15th, 2009:

    I couldn’t get your example code to work without adding the following to the IndexController submitAction:

    $session = Zend_Registry::get(‘session’);

    I’m not sure if the $session variable was suppose to be accessible some other way, or if that was just an oversight in the code.

    I’m pretty green at ZF. Thanks!

  4. 4 Enrico Zimuel said on novembre 18th, 2009:

    Hi John,
    yes you are right, you have to add $sesion= Zend_Registry::get(‘session’); in the sumbitAction. It was an oversight, too many refactoring :)
    I updated the source code, thanks!

  5. 5 dileep said on gennaio 28th, 2010:

    The requested URL /index/login was not found on this server.
    I am getting this error wen i have installed your source code

  6. 6 Enrico Zimuel said on gennaio 29th, 2010:

    You have to check the configuration of your web server. I guess your rewrite rule is not working. If you are using Apache you can read this page: http://framework.zend.com/wiki/display/ZFDEV/Configuring+Your+URL+Rewriter

  7. 7 pzajdel said on marzo 17th, 2010:

    Hi Enrico,

    could you please give me a suggestion where/how to put/invoke code which would check if user is logged and pass this info with a nickname to a layout template and not one view?

  8. 8 Enrico Zimuel said on marzo 18th, 2010:

    For instance, you can insert this code inside the checkSession method of the plugin App_Plugin_SessionCheck of the ZF Secure Login.
    Something like this:
    public function checkSession () {
    $session = Zend_Registry::get(‘session’);
    if (empty($session->username)) {
    $this->getResponse()->setRedirect(‘/index/login’)->sendResponse();
    exit;
    } else {
    $layout = Zend_Layout::getMvcInstance();
    $view= $layout->getView();
    $view->logged= “User {$session->username} is logged!”;
    }
    }
    And insert the print of the logged variable in the layout.

  9. 9 DNoe said on maggio 10th, 2010:

    Greetings -

    I have been teaching myself the Zend Framework and have walked through the Quickstart application provided in the manual. (http://framework.zend.com/manual/en/learning.quickstart.create-model.html) In the portion on creating the model, they use the concept of a “Table Data Gateway” and a “Data Mapper” to map classes to DB tables. I notice that you have not implemented your User model in this way. Is there a reason why?

    It does look like a bit more overhead initially, but it seems as though this approach would provide more separation of code and perhaps increase the code’s extensibility and portability.

    DNoe

  10. 10 Enrico Zimuel said on maggio 11th, 2010:

    Use of Model is always a good practice because you build your PHP application using a better organization of the code, isolating the business logic from the Controller and from the View. I didn’t use a Model in my example because it didn’t contains business logic. The application is just a “toy example” to show how to build a secure login.

  11. 11 Kumar Ishan said on dicembre 20th, 2010:

    hi, its a very good example…..
    but i have one doubt.. why put session into Zend_Registry.. because wherever needed we can create Zend_ Session_Namespace instance and then access its variabe…. because if i have created this instance at any time before then i by recreating its instance i can access those easily….

  12. 12 Enrico Zimuel said on gennaio 2nd, 2011:

    You are right, you can use Zend_Session_Namespace instead of Zend_Registry to manage directly the session data. The only difference is that using Zend_Registry you instantiate the Zend_Session class only one time.

  13. 13 Sameni said on ottobre 30th, 2011:

    Hi, very nice example.
    But is it possible that the download isn’t working? I tried to download the source but it is damaged.

  14. 14 enrico said on ottobre 31st, 2011:

    Hi Sameni,
    i just fixed the issue of the download. Now it works.
    Thanks for your feedback.

  15. 15 Sameni said on ottobre 31st, 2011:

    Thank you, worked this time.

  16. 16 francisco said on febbraio 16th, 2012:

    do I have to create my own “register”/”signup” form and method for hashing the password?
    My question is, does your code only work for login in, not registering?

  17. 17 enrico said on febbraio 16th, 2012:

    The code is just for login, in order to create the password you can use the MD5(CONCAT(salt,password)) of MYSQL where salt is the value stored into the password.salt of application.ini and password is the plain text of the password.


Leave a Reply

  • Anti-Spam Protection by WP-SpamFree