public function authorize(CredentialsInterface $credentials)
    {
        // Check if user can be found
        if ( ! $user = $this->userProvider->findUserByUsername($credentials->getUsername())) {
            throw new UserNotFoundException(sprintf('User "%s" not found', $credentials->getUsername()));
        }

        // Check if password is valid
        if ( ! $this->passwordEncoder->isPasswordValid($user->getPassword(), $credentials->getPassword(), $user->getSalt())) {
            throw new BadCredentialsException(sprintf('Password for user "%s" was incorrect', $credentials->getUsername()));
        }

        // Put user in the auth storage
        $this->storage->setIdentifier($this->storageKey, $user->getUsername());

        $this->user = $user;

        $this->loggedIn = true;

        return $user;
    }
public function authorize(CredentialsInterface $credentials)
    {
        // Check if user can be found
        if ( ! $user = $this->userProvider->findUserByUsername($credentials->getUsername())) {
            throw new UserNotFoundException(sprintf('User "%s" not found', $credentials->getUsername()));
        }

        // Check if password is valid
        if ( ! $this->passwordEncoder->isPasswordValid($user->getPassword(), $credentials->getPassword(), $user->getSalt())) {
            throw new BadCredentialsException(sprintf('Password for user "%s" was incorrect', $credentials->getUsername()));
        }

        // Put user in the auth storage
        $this->storage->setIdentifier($this->storageKey, $user->getUsername());

        $this->user = $user;

        $this->loggedIn = true;

        return $user;
    }
public function authorize ( CredentialsInterface $ credentials ) { // Check if user can be found if ( ! $ user = $ this -> userProvider -> findUserByUsername ( $ credentials -> getUsername ( ) ) ) { throw new UserNotFoundException ( sprintf ( 'User "%s" not found' , $ credentials -> getUsername ( ) ) ) ; } // Check if password is valid if ( ! $ this -> passwordEncoder -> isPasswordValid ( $ user -> getPassword ( ) , $ credentials -> getPassword ( ) , $ user -> getSalt ( ) ) ) { throw new BadCredentialsException ( sprintf ( 'Password for user "%s" was incorrect' , $ credentials -> getUsername ( ) ) ) ; } // Put user in the auth storage $ this -> storage -> setIdentifier ( $ this -> storageKey , $ user -> getUsername ( ) ) ; $ this -> user = $ user ; $ this -> loggedIn = true ; return $ user ; }
Try and authorize a user based on credentials

@param CredentialsInterface $credentials
@return UserInterface
@throws UserNotFoundException
@throws BadCredentialsException
Try and authorize a user based on credentials