Validates a session_version=3 style session object.

@param Array $session the session object
@return Array the session object if it validates, null otherwise
767734
protected function validateSessionObject($session) {
    // make sure some essential fields exist
    if (is_array($session) &&
        isset($session['uid']) &&
        isset($session['access_token']) &&
        isset($session['sig'])) {
      // validate the signature
      $session_without_sig = $session;
      unset($session_without_sig['sig']);
      $expected_sig = self::generateSignature(
        $session_without_sig,
        $this->getApiSecret()
      );
      if ($session['sig'] != $expected_sig) {
        self::errorLog('Got invalid session signature in cookie.');
        $session = null;
      }
      // check expiry time
    } else {
      $session = null;
    }
    return $session;
  }
1367712
private function validateArray(array $array): bool
  {
    foreach ($array as $element)
    {
      if (is_array($element))
      {
        $tmp = $this->validateArray($element);
        if ($tmp===true)
        {
          return true;
        }
      }
      else
      {
        if ($element!==null && $element!==false && $element!=='')
        {
          return true;
        }
      }
    }

    return false;
  }
810539
public function validate($token) {
		if( !isset($_SESSION[self::SESSION_KEY][$this->name]) ) {
			return false;
		}
		$TOKEN_SESSION = &$_SESSION[self::SESSION_KEY][$this->name];
		if( empty($token) || empty($TOKEN_SESSION) || !isset($TOKEN_SESSION[$token]) ) {
			return false;
		}
		$TOKEN_SESSION[$token]++;
		if( $TOKEN_SESSION[$token] >= $this->maxUsage ) {
			unset($TOKEN_SESSION[$token]);
		}
		return true;
	}
1338792
private static function validate() {
	if (self::is_active() == false) {
		$exception = bootstrap::get_library('exception');
		throw new $exception('inactive session');
	}
	
	if (empty($_SESSION['_session_type']) || empty($_SESSION['_session_last_active'])) {
		return false;
	}
	
	// throw away expired (replaced) sessions
	if (!empty($_SESSION['_session_expire_at']) && $_SESSION['_session_expire_at'] < time()) {
		return false;
	}
	
	// last_active short enough ago
	$type_duration = self::$type_durations[ $_SESSION['_session_type'] ];
	$active_enough = ($_SESSION['_session_last_active'] > (time() - $type_duration));
	if ($active_enough == false) {
		return false;
	}
	
	return true;
}
969254
public function validate($entity)
    {
        $errors = $this->validator->validate($entity);

        $dataErrors = [];

        /** @var ConstraintViolation $error */
        foreach ($errors as $error) {
            if (!isset($dataErrors[$error->getPropertyPath()])) {
                $dataErrors[$error->getPropertyPath()] = [];
            }

            $dataErrors[$error->getPropertyPath()][] = $error->getMessage();
        }

        return $dataErrors;
    }
645838
public function validate(array $array)
	{
		$messages = [];
		foreach ($this->metadata->fields as $field)
		{
			$value = array_key_exists($field, $array)? $array[$field] : null;
			if (!(($value === null) && $this->metadata->nullables[$field]))
			{
				$validator = $this->getValidator($field);
				if (!$validator->isValid($value))
				{
					$messages[$field] = $validator->getMessages();
				}
			}
		}
		$globalValidator = $this->getValidator(self::GLOBAL_VALIDATOR_KEY);
		if (!$globalValidator->isValid($array))
		{
			$messages[self::GLOBAL_VALIDATOR_KEY] = $globalValidator->getMessages();
		}
		return $messages;
	}
669357
protected function validate_php( $php ) {
		$result = $required = array();

		foreach ( $php as $type => $data ) {
			switch ( $type ) {
				case 'version':
					$result[ $type ]   = version_compare( phpversion(), $data, $this->version_compare_operator );
					$required[ $type ] = $data;
					break;

				case 'extensions':
					// Check that all required PHP extensions are loaded.
					foreach ( (array) $data as $extension ) {
						if ( $extension && is_string( $extension ) ) {
							$result[ $type ][ $extension ] = extension_loaded( $extension );
							$required[ $type ][]           = $extension;
						}
					}

					break;
			}
		}

		$this->results['php']  = $result;
		$this->required['php'] = $required;
	}
1217263
protected function validateReset(array $credentials)
	{
		if (is_null($user = $this->getUser($credentials)))
		{
			return PasswordBrokerContract::INVALID_USER;
		}

		if ( ! $this->validateNewPassword($credentials))
		{
			return PasswordBrokerContract::INVALID_PASSWORD;
		}

		if ( ! $this->tokens->exists($user, $credentials['token']))
		{
			return PasswordBrokerContract::INVALID_TOKEN;
		}

		return $user;
	}
1183028
public function checkSession()
	{
		// Get session token
		$session_token = isset($_COOKIE[$this->cookie_name]) ? $_COOKIE[$this->cookie_name]
			: (isset($_SERVER['HTTP_AUTH_TOKEN']) ? $_SERVER['HTTP_AUTH_TOKEN'] : null);

		// Get reference to session state machine
		if ($session_token) {
			// Get session machine ref
			$session_id = (array) $this->session_machine_ref_prefix;
			$session_id[] = $session_token;
			$this->session_machine = $this->smalldb->ref($session_id);

			// Check session
			if ($this->session_machine->state == '') {
				// Invalid token
				$this->session_machine = $this->smalldb->ref($this->session_machine_null_ref);
			} else {
				// TODO: Validate token, not only session existence, and check whether session is in valid state (invoke a transition to check).

				// TODO: Session should tell how long it will last so the cookie should have the same duration.

				// Token is good - refresh cookie
				setcookie($this->cookie_name, $session_token, time() + $this->cookie_ttl, '/', null, !empty($_SERVER['HTTPS']), true);
			}
		} else {
			// No token
			$this->session_machine = $this->smalldb->ref($this->session_machine_null_ref);
		}

		// Update token on state change
		$t = $this;
		$this->session_machine->afterTransition()->addListener(function($ref, $transition_name, $arguments, $return_value, $returns) use ($t) {
			if (!$ref->state) {
				// Remove cookie when session is terminated
				setcookie($t->cookie_name, null, time() + $t->cookie_ttl, '/', null, !empty($_SERVER['HTTPS']), true);
				if (isset($_SESSION)) {
					// Kill PHP session if in use
					session_regenerate_id(true);
				}
			} else {
				// Update cookie on state change
				setcookie($t->cookie_name, $ref->id, time() + $t->cookie_ttl, '/', null, !empty($_SERVER['HTTPS']), true);
			}
		});

		// Everything else is up to the state machine
	}
562291
public function validSession ()
	{
		
		// Get session
		
		$session	= $this->getSessionData ();
		
		// Check session is valid
		
		if ($this->checkSession ($session) !== TRUE)
		{
			$this->loggedIn	= FALSE;
			return FALSE;
		}
		
		// If the user is not active or the active status has changed
		
		if ($session['active'] !== $this->iget ('active') || !$this->iget ('active'))
		{
			$this->loggedIn	= FALSE;
			return FALSE;
		}
		
		// Check if the session has timed out
		
		if ($this->session ()->timedOut ($session['last_action']))
		{
			$this->loggedIn	= FALSE;
			return FALSE;
		}
		
		// Set login status
		
		$this->loggedIn	= TRUE;
		
		// Return TRUE
		
		return TRUE;
		
	}
785037
function requireValidSession (session) {
    assert.ok(session && typeof session === 'object' && typeof session.sessionId === 'string' && Array.isArray(session.roles), 'session with sessionId and roles required to request access')
}
1277668
static function singleton(Session $session = null)
        {
            if (self::$singleton == null) {
                self::$singleton = new SessionFlash($session);
            }

            return self::$singleton;
        }
1224273
private static function session($session)
    {
        $files = ['Session'];
        $folder = static::$root.'Storage'.'/';

        self::call($files, $folder);

        $files = ['SessionKeyNotFoundException', 'SessionSurfaceIsOffException'];
        $folder = static::$root.'Storage/Exceptions'.'/';

        self::call($files, $folder);

        //Initiat the class
        if ($session) {
            Session::ini();
        }
    }
826020
public static function validate($access)
    {
        $lowercaseAccess = \strtolower($access);

        if ('subscription' === $lowercaseAccess || 'registration' === $lowercaseAccess) {
            return \ucfirst($lowercaseAccess);
        }

        return false;
    }
118201
public function showLogin(array $request = [])
    {
        $messages = [
            'error' => '',
            'info' => '',
            'success' => '',
            'warning' => ''
        ];
        if (empty($request['m']) === false) {
            if ($request['m'] == 1) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['info'] = 'Please activate your account through the confirmation email sent.';
                $messages['success'] = 'User registered successfully.';
            } elseif ($request['m'] == 2) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['info'] = 'Password reset email sent to account. Please reset your password through the link in the email.';
            } elseif ($request['m'] == 3) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 422', true, 422);
                }
                $messages['error'] = 'Invalid password reset link.';
            } elseif ($request['m'] == 4) {
                $messages['success'] = 'Password reset successfully.';
            } elseif ($request['m'] == 5) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['success'] = 'Account deleted successfully.';
            } elseif ($request['m'] == 6) {
                if (headers_sent() === false) {
                    header('X-PHP-Response-Code: 202', true, 202);
                }
                $messages['success'] = 'Account sessions invalidated successfully.';
            }
        }
        return $this->templates->render("Auth::Login", [
            "messages" => $messages,
            "username" => ''
        ]);
    }
1258408
public function getLastAuthenticationError($clearSession = true)
    {
        $request = $this->getRequest();
        $session = $request->getSession();
        $authenticationException = null;

        if ($request->attributes->has(Security::AUTHENTICATION_ERROR)) {
            $authenticationException = $request->attributes->get(Security::AUTHENTICATION_ERROR);
        } elseif (null !== $session && $session->has(Security::AUTHENTICATION_ERROR)) {
            $authenticationException = $session->get(Security::AUTHENTICATION_ERROR);

            if ($clearSession) {
                $session->remove(Security::AUTHENTICATION_ERROR);
            }
        }

        return $authenticationException;
    }
539889
protected function validate(array &$data)
    {
        $this->validateVersion();
        $this->validateExtensions();
        $this->validateIni();
        $data = array_merge($data, ['messages' => $this->messages]);
        return $data;
    }