Вы можете реализовать пользовательский провайдер. Пример:
class UserRepository extends ServiceEntityRepository implements UserLoaderInterface
{
public function __construct(ManagerRegistry $registry)
{
parent::__construct($registry, User::class);
}
/**
* Loads the user for the given username.
*
* This method must return null if the user is not found.
*
* @param $usernameOrEmail
* @return UserInterface|null
* @throws \Doctrine\ORM\NonUniqueResultException
*/
public function loadUserByUsername($usernameOrEmail)
{
return $this->createQueryBuilder('u')
->where('u.username = :query OR u.email = :query')
->setParameter('query', $usernameOrEmail)
->getQuery()
->getOneOrNullResult();
}
}