/** * Display the login box or process a login on submission. */ public function loginAction() { if ($this->getAuth()->getIdentity()) { $this->addMessage(_('You are already logged in.'), ViMbAdmin_Message::INFO); $this->_redirect('domain/list'); } // make sure we have some users if (AdminTable::getCount() == 0) { $this->_redirect('auth/setup'); } $auth = Zend_Auth::getInstance(); $loginForm = new ViMbAdmin_Form_Auth_Login(); if ($this->getRequest()->isPost() && $loginForm->isValid($_POST)) { try { $authAdapter = new ViMbAdmin_Auth_DoctrineAdapter($loginForm->getValue('username'), AdminTable::hashPassword($loginForm->getValue('password'), $this->_options['securitysalt'])); $result = $auth->authenticate($authAdapter); switch ($result->getCode()) { case Zend_Auth_Result::SUCCESS: $identity = $auth->getIdentity(); $this->getLogger()->info("Admin {$identity['username']} logged in"); $this->_redirect('domain/list'); break; default: $this->addMessages($result->getMessages(), ViMbAdmin_Message::ERROR); $this->getLogger()->debug("Bad login for {$loginForm->getValue('username')}: " . implode(' -- ', $result->getMessages())); break; } } catch (Zend_Auth_Adapter_Exception $e) { $this->getLogger()->err("Exception in AuthController::loginAction: " . $e->getMessage()); $this->addMessage(_("System error during login - please see system logs or contact your system administrator."), ViMbAdmin_Message::ERROR); } } $this->view->loggedOut = $this->_getParam('out', false); $this->view->loginForm = $loginForm; }
/** * Sets the admin password and optionally saves it to the database. * * @param string $password the password * @param string $salt default '' a random security salt to prevent dictionary lookups of the hashed value * @param boolean $save default false set to true if you want to update the database * @return object Admin returns a reference to this object for method chaining. */ public function setPassword($password, $salt = '', $save = false) { $this->password = AdminTable::hashPassword($password, $salt); if ($save) { $this->save(); } return $this; }