Removes all valid user sessions.
(causes the user to login again)

@param string $username
@param string $session In case you want to revoke a particular session.

@throws LoginException
337217
public function revokeSessions($username, $session = '')
    {
        $this->username = $username;
        if ($session == '') {
            $newSessions = [];
        } else {
            $sessions = $this->getMeta()->sessions;

            $newSessions = [];
            foreach ($sessions as $s) {
                if ($s['sid'] != $session) {
                    $newSessions[] = $s;
                }
            }
        }

        $this->getMeta()->sessions = $newSessions;
        $this->getMeta()->save();
    }
21055
public function destroySession() {
        if (session_status() == PHP_SESSION_ACTIVE) {
            // unset all session variables
            $_SESSION = [];

            // delete the session cookie
            if (ini_get_bool('session.use_cookies')) {
                $params = session_get_cookie_params();
                setcookie($name=session_name(), $value='', $expire=time()-1*DAY, $params['path'    ],
                                                                                 $params['domain'  ],
                                                                                 $params['secure'  ],
                                                                                 $params['httponly']);
            }
            session_destroy();                      // TODO: check if SID is reset
        }
    }
418116
void destroy( HttpSession session )
    {
        onDestroy();    // for backwards compatiblity
        super.destroy( session );

        //
        // We may have lost our transient ServletContext reference.  Try to get the ServletContext reference from the
        // HttpSession object if necessary.
        //
        ServletContext servletContext = getServletContext();
        if ( servletContext == null && session != null ) servletContext = session.getServletContext();

        if ( servletContext != null )
        {
            PageFlowEventReporter er = AdapterManager.getServletContainerAdapter( servletContext ).getEventReporter();
            er.flowControllerDestroyed( this, session );
        }
    }
1272435
public function clear(string $variableName = null): Session
    {
        if ($variableName === null) {
            throw new BadMethodCallException('Variable name must be specified');
        }
        if ($variableName === '_MFREG_') {
            throw new InvalidArgumentException('_MFREG_ variable name is not allowed');
        }
        if (isset($this->variables[$variableName])) {
            unset($_SESSION[$variableName]);
            unset($this->variables[$variableName]);
        }

        return static::$instance;
    }
1214981
public function logout()
		{

			// Am I authenticated?
			if ($this->isAuthenticated() == false) {

				// Cannot logout!
				return false;

			}

			// Destroy my session
			$this->_authenticated = false;
			unset($_SESSION[self::$_sessionPrefix . $this->name]);
			$this->_user = null;
			return true;

		}
1001616
private function removeValues($prefix, SessionInterface $session)
    {
        foreach ($session->all() as $key => $value) {
            if (0 === strpos($key, $prefix)) {
                $session->remove($key);
            }
        }
    }
1371442
public function deleteUser($userLogin)
    {
        Piwik::checkUserHasSuperUserAccess();
        $this->checkUserIsNotAnonymous($userLogin);

        $this->checkUserExist($userLogin);

        if ($this->isUserTheOnlyUserHavingSuperUserAccess($userLogin)) {
            $message = Piwik::translate("UsersManager_ExceptionDeleteOnlyUserWithSuperUserAccess", $userLogin)
                        . " "
                        . Piwik::translate("UsersManager_ExceptionYouMustGrantSuperUserAccessFirst");
            throw new Exception($message);
        }

        $this->model->deleteUserOnly($userLogin);
        $this->model->deleteUserAccess($userLogin);

        Cache::deleteTrackerCache();
    }
777831
public static function delete($name)
    {
        empty(self::$init) && self::init();

        $session = self::get($name);
        if (is_string($session)) {
            unset($_SESSION[$name]);
        }

        if (is_array($session)) {
            $_SESSION[$name] = [];
        }
        return true;
    }
467910
public function revokeSession()
    {
        try {
            // Only show this flash if there are users in the system.
            // Not when we're about to get redirected to the "first users" screen.
            if ($this->getRepositoryUsers()->count() > 0) {
                $this->flashLogger->info(Trans::__('general.phrase.access-denied-logged-out'));
            }
        } catch (TableNotFoundException $e) {
            // If we have no table, then we definitely have no users
        }

        // Remove all auth tokens when logging off a user
        if ($sessionAuth = $this->session->get('authentication')) {
            try {
                $this->getRepositoryAuthtoken()->deleteTokens($sessionAuth->getUser()->getId());
            } catch (TableNotFoundException $e) {
                // Database tables have been dropped
            } catch (InvalidFieldNameException $e) {
                // Database tables need updating
            } catch (DriverException $e) {
                // Database tables need updating
            }
        }

        $this->session->remove('authentication');
        $this->session->migrate(true, 0);

        return false;
    }
1090967
@Override
	public void deleteSession(String sessionName) {
		logger.debug("deleteSession " + sessionName);
	    if (databaseServer == null) {
	    	return;
	    }
        databaseServer = null;
    }
869513
public function logout($authToken)
    {
        // get user from firewall
        $this->security($this->fwName)->getToken()->setTokenString($authToken);
        $user = $this->security($this->fwName)->getUser();
        if (!$user->isAuthenticated()) {
            throw new LoginException('User is not authenticated', 6);
        }

        // extract username
        $this->username = $user->getUsername();

        // logout on firewall
        $this->security($this->fwName)->processLogout();

        // delete the session
        $this->revokeSessions($this->username, $authToken);
    }
1221788
public function removeUser($username)
    {
        // This preserves compatibility for the old policy parameter.
        $params = [];

        $url = UrlHelper::buildUrl(Urls::URL_USER, [$username]);
        $url = UrlHelper::appendParamsUrl($url, $params);
        $this->getConnection()->delete($url);

        return true;
    }
492321
@Override
	public void deleteSession(String sessionName) {
		logger.debug("deleteSession " + sessionName);
	    if (databaseServer == null) {
	    	return;
	    }
        try {
			databaseServer.shutdown(false);
		} catch (SQLException e) {
            logger.error(e.getMessage(), e);
		}
		
        deleteDbFile(new File(sessionName));
        deleteDbFile(new File(sessionName + ".data"));
        deleteDbFile(new File(sessionName + ".script"));
        deleteDbFile(new File(sessionName + ".properties"));
        deleteDbFile(new File(sessionName + ".backup"));
        deleteDbFile(new File(sessionName + ".lobs"));
        
        databaseServer = null;
    }
387329
public static function clearSession(){
        session_destroy();
        self::$instance->invalidate();
        setcookie(self::$instance->getName(), self::$instance->getId(), time() - 3600 ,'/');
        return true;
    }
291964
protected function forgetMe($username, $password)
    {
        $melisCoreConfig = $this->serviceLocator->get('MelisCoreConfig');
        $authCookieConfig = $melisCoreConfig->getItem('meliscore/datas/default/auth_cookies');
        $expire = $authCookieConfig['expire'];


        $user = new SetCookie('cookie1', $this->crypt($username), strtotime($expire, time()));
        $remember = new SetCookie('remember', 0, strtotime($expire, time()));

        $this->getResponse()->getHeaders()->addHeader($user);
        $this->getResponse()->getHeaders()->addHeader($remember);

        // add code here to remove session
        $sessionManager = new SessionManager();
        $sessionManager->forgetMe();
        Container::setDefaultManager($sessionManager);
    }
1160632
public function login($username, $password)
    {
        $user = $this->getUserByField("username", $username);

        if ($password === null) {
            throw new Exception("Empty password field.");
        }

        if ($user->id === null) {
            throw new Exception("Error, not valid credentials.");
        }

        if ($user->deleted !== null) {
            throw new Exception("User deleted.");
        }

        if ((int)$user->enabled === 0) {
            throw new Exception("Error, disabled account.");
        }

        if ($this->validatePassword($password, $user->password)) {
            $this->session->set("user", $user);
            return true;
        }
        throw new Exception("Error, not valid credentials.");
    }
656470
private function revokeMembership($user)
    {
        try {

            foreach($user->membershipList as $group) {
                if ($group->resync_on_login) {
                    $user->membershipList()->detach($group);
                }
            }

        } catch (\Exception $ex) {
            Log::error('Exception revoking local group membership for user: ' . $user->username . ', Exception message: ' . $ex->getMessage());
            Log::error($ex->getTraceAsString());
        }

    }