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
  • 42,438
  • 18
  • 116
  • 138
olek07
  • 513
  • 2
  • 7
  • 21
  • 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

5

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
  • 616
  • 5
  • 16