/** * Add a new application password: ajax action * * @param \thebuggenie\core\framework\Request $request */ public function runAccountAddPassword(framework\Request $request) { $this->forward403unless($this->getUser()->hasPageAccess('account')); $name = trim($request['name']); if ($name) { framework\Logging::log('Adding new application password for user.', 'account', framework\Logging::LEVEL_INFO); $password = new entities\ApplicationPassword(); $password->setUser($this->getUser()); $password->setName($name); $visible_password = strtolower(entities\User::createPassword()); // Internally creates a hash from this visible password & crypts that hash for storage $password->setPassword($visible_password); $password->save(); $spans = ''; for ($cc = 0; $cc < 4; $cc++) { $spans .= '<span>' . substr($visible_password, $cc * 4, 4) . '</span>'; } return $this->renderJSON(array('password' => $spans)); } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $this->getI18n()->__('Please enter a valid name'))); } }
/** * Change password ajax action * * @param \thebuggenie\core\framework\Request $request */ public function runAccountAddPassword(framework\Request $request) { $this->forward403unless($this->getUser()->hasPageAccess('account')); if (trim($request['name'])) { $password = new entities\ApplicationPassword(); $password->setUser($this->getUser()); $password->setName(trim($request['name'])); $visible_password = strtolower(entities\User::createPassword()); $password->setPassword($visible_password); $password->save(); $spans = ''; for ($cc = 0; $cc < 4; $cc++) { $spans .= '<span>' . substr($visible_password, $cc * 4, 4) . '</span>'; } return $this->renderJSON(array('password' => $spans)); } else { $this->getResponse()->setHttpStatus(400); return $this->renderJSON(array('error' => $this->getI18n()->__('Please enter a valid name'))); } }