/** * The handler for the own details. * * @param mixed $handler_id the array key from the request array * @param array $args the arguments given to the handler * @param Array &$data The local request data. * @return boolean Indicating success. */ function _handler_changePassword($handler_id, $args, &$data) { $this->_request_data['name'] = "fi.kilonkipinat.account"; $title = $this->_l10n_midcom->get('index'); $_MIDCOM->set_pagetitle(":: {$title}"); $this->_component_data['active_leaf'] = "change_password"; $message = ''; $person = new fi_kilonkipinat_account_person_dba($_MIDGARD['user']); if (isset($_POST) && isset($_POST['old_pass']) && $_POST['old_pass'] != '') { $old_pass = trim($_POST['old_pass']); $auth_user = midgard_user::auth($person->username, $old_pass, self::sitegroup_for_auth(), false); if (!$auth_user) { $message = '<h3>Virhe</h3>Väärä vanha salasana!!!'; } elseif (isset($_POST['new_pass']) && isset($_POST['new_pass2']) && strlen(trim($_POST['new_pass'])) >= $this->_config->get('password_min_length')) { $new_pass = trim($_POST['new_pass']); $new_pass2 = trim($_POST['new_pass2']); if ($new_pass == $new_pass2) { // Enforce crypt mode $salt = chr(rand(64, 126)) . chr(rand(64, 126)); $crypt_password = crypt($new_pass, $salt); $person->password = $crypt_password; $person->update(); $message = '<h3>Salasana vaihdettu</h3>'; $_MIDCOM->auth->_auth_backend->create_login_session($person->username, $new_pass); } else { $message = '<h3>Virhe</h3>Varmistussalasana ei täsmää'; } } else { $message = '<h3>Virhe</h3>Uusi salasana liian lyhyt'; } } $this->_request_data['person'] = $person; $this->_request_data['messages'] = $message; return true; }
public function login($username, $password) { if (method_exists('midgard_connection', 'get_sitegroup')) { // Midgard 8.09 or 9.03 authentication API with sitegroups if (!$this->sitegroup) { // In Midgard2 we need current SG name for authentication $this->sitegroup = midgardmvc_core::get_instance()->dispatcher->get_midgard_connection()->get_sitegroup(); } $this->user = midgard_user::auth($username, $password, $this->sitegroup); if (!$this->user) { midgardmvc_core::get_instance()->log(__CLASS__, "Failed authentication attempt for {$username}", 'warning'); return false; } return true; } // Use Midgard 9.09 authentication API try { $user = new midgard_user($this->prepare_tokens($username, $password)); if ($user->login()) { $this->user = $user; } } catch (Exception $e) { midgardmvc_core::get_instance()->log(__CLASS__, "Failed authentication attempt for {$username}", 'warning'); return false; } return true; }
public function prepare_storage() { // Generate tables midgard_storage::create_base_storage(); // And update as necessary $re = new ReflectionExtension('midgard2'); $classes = $re->getClasses(); foreach ($classes as $refclass) { if ($refclass->isAbstract() || $refclass->isInterface()) { continue; } $type = $refclass->getName(); if (!is_subclass_of($type, 'MidgardDBObject')) { continue; } if (midgard_storage::class_storage_exists($type)) { // FIXME: Skip updates until http://trac.midgard-project.org/ticket/1426 is fixed continue; if (!midgard_storage::update_class_storage($type)) { $this->markTestSkipped('Could not update ' . $type . ' tables in test database'); } continue; } if (!midgard_storage::create_class_storage($type)) { $this->markTestSkipped('Could not create ' . $type . ' tables in test database'); } } // And update as necessary return; if (!midgard_user::auth('root', 'password')) { echo "auth failed\n"; $this->markTestSkipped('Could not authenticate as ROOT'); } }
public function login($username, $password) { if (extension_loaded('midgard2')) { // FIXME: Remove this once midgard_user::auth works in Midgard 2.x return true; } $this->user = midgard_user::auth($username, $password, null); if (!$this->user) { return false; } return true; }
/** * Perform a login against the midgard backend * * @param string $username The username as entered * @param string $password The password as entered * @param boolean $trusted Use trusted auth (mgd1 only, ATM) * @return mixed The appropriate object or false */ public static function login($username, $password, $trusted = false) { if (method_exists('midgard_user', 'login')) { // Ratatoskr $login_tokens = array('login' => $username, 'authtype' => $GLOBALS['midcom_config']['auth_type']); if (!$trusted) { $login_tokens['password'] = self::prepare_password($password); } try { $user = new midgard_user($login_tokens); } catch (midgard_error_exception $e) { return false; } if (!$user->login()) { return false; } return $user; } else { // Ragnaroek $sg_name = ''; $mode = $GLOBALS['midcom_config']['auth_sitegroup_mode']; if ($mode == 'auto') { $mode = self::_get('sitegroup') == 0 ? 'not-sitegrouped' : 'sitegrouped'; } if ($mode == 'sitegrouped') { $sitegroup = new midgard_sitegroup(self::_get('sitegroup')); $sg_name = $sitegroup->name; } $stat = midgard_user::auth($username, $password, $sg_name, $trusted); if (!$stat && $GLOBALS['midcom_config']['auth_type'] == 'Plaintext' && strlen($password) > 11) { //mgd1 has the password field defined with length 13, but it doesn't complain //when saving a longer password, it just sometimes shortens it, so we try the //shortened version here (we cut at 11 because the first two characters are **) $stat = midgard_user::auth($username, substr($password, 0, 11), $sg_name, $trusted); } return $stat; } }
/** * Executes the login to midgard. * @param username * @param password * @return bool */ private function do_midgard_login($username, $password) { if (method_exists('midgard_connection', 'get_sitegroup')) { // Midgard 8.09 or 9.03 authentication API with sitegroups if (!$this->sitegroup) { // Sitegroups are only used in Midgard 9.03 and older $this->sitegroup = midgardmvc_core::get_instance()->dispatcher->get_midgard_connection()->get_sitegroup(); } if ($this->sitegroup) { $this->user = midgard_user::auth($username, '', $this->sitegroup, $this->trusted_auth); } else { $this->user = midgard_user::auth($username, '', $this->trusted_auth); } // Don't allow trusted auth for admin users if ($this->trusted_auth && !empty($this->user) && $this->user->is_admin()) { // Re-check using password for admin users $this->user = midgard_user::auth($username, $password, $this->sitegroup, false); } if (!$this->user) { midgardmvc_core::get_instance()->log(__CLASS__, "Failed authentication attempt for {$username}", 'warning'); $this->session_cookie->delete_login_session_cookie(); return false; } return true; } // Use Midgard 9.09 authentication API try { $user = new midgard_user($this->prepare_tokens($username, $password)); if ($user->login()) { $this->user = $user; } } catch (Exception $e) { midgardmvc_core::get_instance()->log(__CLASS__, "Failed authentication attempt for {$username}", 'warning'); $this->session_cookie->delete_login_session_cookie(); return false; } return true; }