public function indexAction() { if (Zend_Auth::getInstance()->hasIdentity()) { $this->_redirect('admin/index'); } // Create form login $form = new Login_Form_Login(); $request = $this->getRequest(); // Is post if ($request->isPost()) { if ($form->isValid($request->getPost())) { // Get values from form $user = $form->getValue('username'); $password = $form->getValue('password'); $authAdapter = $this->getAuthAdapter(); $authAdapter->setIdentity($user)->setCredential($password); $auth = Zend_Auth::getInstance(); $result = $auth->authenticate($authAdapter); # is the user a valid one? if ($result->isValid()) { # all info about this user from the login table # ommit only the password, we don't need that $userInfo = $authAdapter->getResultRowObject(null, 'password'); # the default storage is a session with namespace Zend_Auth $authStorage = $auth->getStorage(); $authStorage->write($userInfo); $this->_redirect('admin/index'); } else { $errorMessage = "Wrong username or password provided. Please try again."; } } } $errorMessage = ""; // View $this->view->title = 'Login'; $this->view->form = $form; }