Validate the user is authorized.

@param array $user
@return bool
@throws ForbiddenException
@throws UnauthorizedException
186909
public function isAuthorized($user = null) {
        if (!$user) {
            throw new ForbiddenException(__d('admin', 'Invalid User'));
        }

        $aro = Admin::introspectModel('Admin.RequestObject');

        if ($aro->isAdmin($user['id'])) {
            if (!$this->Session->read('Admin.crud')) {
                $this->Session->write('Admin.crud', $aro->getCrudPermissions($user['id']));
            }

            return true;
        }

        throw new UnauthorizedException(__d('admin', 'Insufficient Access Permissions'));
    }
1244049
public function validateToken(CanResetPasswordContract $user, array $credentials): bool
    {
        $payload = $this->buildPayload($user, $credentials['email'], $credentials['expiration']);

        return hash_equals($credentials['token'], hash_hmac('sha256', $payload, $this->getKey()));
    }
1200392
public function is_available(User $user)
    {
        if (! $this->app['registration.manager']->isRegistrationEnabled()) {
            return false;
        }

        return $this->app->getAclForUser($user)->has_right(\ACL::CANADMIN);
    }
302580
public function canBeAuthenticated(Authenticatable $user, $guards)
    {
        $userGuard = AuthConfigHelper::getUserGuard($user);

        return in_array($userGuard, $guards);
    }
1017305
protected function validateData(User $user, $username, $password, $passwordConfirmed)
    {
        $errors = array();
        
        // Username
        if ($this->isUsernameInUse($username, $user)) {
            $errors[] = new Error(Error::GENERAL_ERROR, $this->translate('The username is already in use.', '\\Zepi\\Web\\AccessControl'));
        }        
        
        // If the user is new or the password is not empty we need to validate
        // the password.
        if ($this->shouldValidatePassword($user, $password)) {
            // Password
            if (strlen($password) < 8) {
                $errors[] = new Error(Error::WRONG_INPUT, $this->translate('The password needs at least 8 characters.', '\\Zepi\\Web\\AccessControl'));
            }
            
            if ($password != $passwordConfirmed) {
                $errors[] = new Error(Error::WRONG_INPUT, $this->translate('The passwords are not equal.', '\\Zepi\\Web\\AccessControl'));
            }
        }
        
        if (count($errors) > 0) {
            return $errors;
        }
        
        return true;
    }
790997
public function userHasAccess(User $user)
    {
        if ($this->getWhitelisted() === false) {
            return true;
        }

        $criteria = Criteria::create()
                ->where(Criteria::expr()->eq('user', $user))
                ->setMaxResults(1);

        $serverUsers = $this->users->matching($criteria);
        if ($serverUsers->count() === 0) {
            return false;
        }

        $serverUser = $serverUsers->first();

        if ($serverUser->getBanned() === true) {
            return false;
        }

        if ($this->getRequiresApproval() === true && $serverUser->getApproved() === false) {
            return false;
        }

        return true;
    }
990046
public function logInRememberMe(array $user): bool
    {
        if (!$user) {
            return false;
        }

        $this->session->set('user', $user);

        return true;
    }
473010
public function validateCredentials(UserInterface $user, array $credentials)
	{
		try
		{
			$result = Kinvey::login($credentials);
			$user->_kmd = $result['_kmd'];
		}
		catch (KinveyResponseException $e)
		{
			if ($e->getResponse()->getStatusCode() === 401)
			{
				return false;
			}
			else
			{
				throw $e;
			}
		}

		return true;
	}
223217
public function validateCredentials(Authenticatable $user, array $credentials)
    {
        if (! app('hash')->check($credentials['password'], $user->password)) {
            return false;
        }

        return true;
    }
996941
public function isFullyAuthenticated($user = null)
    {
        $user = $user ?: $this->getUser();

        return $this->isGranted('IS_AUTHENTICATED_FULLY', $user);
    }
723325
protected function verifyUser($user)
    {
        $user->verified = true;
        $user->verified_at = new Carbon('now');

        $user->save();

        Auth::guard($this->getGuard())->login($user);
    }
746575
public function iAuthenticateAs($user)
    {
        if (!isset($this->users[$user])) {
            throw new ClientErrorResponseException(
                'User ' . $user . ' does not exist'
            );
        }

        $this->addGuzzleHeader(
            'Authorization',
            'Bearer ' . $this->users[$user]
        );
    }
383102
protected function canBind(Authenticatable $user) : bool
    {
        return array_key_exists(HasLdapUser::class, class_uses_recursive($user)) && is_null($user->ldap);
    }
1100656
protected function validateReset(array $credentials)
    {
        if (is_null($user = $this->getUser($credentials))) {
            return static::INVALID_USER;
        }

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

        if (! $this->validateToken($user, $credentials)) {
            return static::INVALID_TOKEN;
        }

        if (! $this->validateTimestamp($credentials['expiration'])) {
            return static::EXPIRED_TOKEN;
        }

        return $user;
    }
742759
public function activate(User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        try {
            ($active = $user->isActive()) ? $user->deactivate() : $user->activate();

            $message = $this->transNotification(
                $active ? 'disabled' : 'enabled',
                ['name' => $user->full_name],
                $user->toArray()
            );

            return $this->jsonResponseSuccess(compact('message'));
        }
        catch (\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
202931
private function isAccessAuthorized($uri)
    {
        foreach ($this->forbiddenUriPatterns as $forbiddenUriPattern)
        {
            if (preg_match("@$forbiddenUriPattern@", $uri))
            {
                return false;
            }
        }
        return true;
    }
94397
public function authorize($user, Request $request)
    {
        if ($request->is('userAdmin')) {
            return true;
        }

        $user = user();
        $path = $this->requestPath($request);
        $cacheKey = 'permissions_' . intval($user->id);
        $permissions = Cache::read($cacheKey, 'permissions');

        if ($permissions === false) {
            $permissions = [];
            Cache::write($cacheKey, [], 'permissions');
        }

        if (!isset($permissions[$path])) {
            $allowed = $user->isAllowed($path);
            $permissions[$path] = $allowed;
            Cache::write($cacheKey, $permissions, 'permissions');
        } else {
            $allowed = $permissions[$path];
        }

        return $allowed;
    }