public function authenticate($username, $password)
    {
        try {
            $user = $this->userProvider->loadUserByUsername($username);
        } catch (UsernameNotFoundException $e) {
            return null;
        }

        $valid = $this->encoderFactory->getEncoder($user)->isPasswordValid(
            $user->getPassword(),
            $password,
            $user->getSalt()
        );

        if ($valid) {
            return $user;
        }

        return null;
    }
public function authenticate($username, $password)
    {
        try {
            $user = $this->userProvider->loadUserByUsername($username);
        } catch (UsernameNotFoundException $e) {
            return null;
        }

        $valid = $this->encoderFactory->getEncoder($user)->isPasswordValid(
            $user->getPassword(),
            $password,
            $user->getSalt()
        );

        if ($valid) {
            return $user;
        }

        return null;
    }
public function authenticate ( $ username , $ password ) { try { $ user = $ this -> userProvider -> loadUserByUsername ( $ username ) ; } catch ( UsernameNotFoundException $ e ) { return null ; } $ valid = $ this -> encoderFactory -> getEncoder ( $ user ) -> isPasswordValid ( $ user -> getPassword ( ) , $ password , $ user -> getSalt ( ) ) ; if ( $ valid ) { return $ user ; } return null ; }
Authenticates user and returns

@param string $username
@param string $password

@return IUser|null
Authenticates user and returns