1

I'm using the login form from Symfony, but I can't login, if the entered username is 'FOO' and in the DB is stored 'foo'. I'm using Postgres. It means the username-field is case sensitive. What can I do?

yivi
  • 1
  • 16
  • 86
  • 115
olek07
  • 435
  • 1
  • 7
  • 17
  • If you are in control over what column type is used, maybe you can solve it this way: https://stackoverflow.com/a/4482278/10955263 – 04FS May 17 '19 at 09:16
  • 1
    @olek07 I think in your case you need to update your UserProvider, check https://symfony.com/doc/current/security/user_provider.html, think about updating `loadUserByUsername()` method to remove the sensitive check for your username value – Mohamed Radhi Guennichi May 17 '19 at 09:17
  • Yes, It works. Thank's a lot. – olek07 May 17 '19 at 09:27

1 Answers1

4

This depends mainly on your Database-Server. MySQL is case insensitive, PostgreSQL is case sensitive.

But you can write query Like this

$this->createQueryBuilder('user')
            ->where('LOWER(user.username) = :username')
            ->setParameter('username', strtolower($username))
            ->getQuery()
            ->getResult()
            ;

Nairi Abgaryan
  • 337
  • 1
  • 8