File tree Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Expand file tree Collapse file tree 2 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -177,16 +177,28 @@ public function findByCredentials(array $credentials): ?User
177177 $ email = $ credentials ['email ' ] ?? null ;
178178 unset($ credentials ['email ' ]);
179179
180+ if ($ email === null && $ credentials === []) {
181+ return null ;
182+ }
183+
180184 // any of the credentials used should be case-insensitive
181185 foreach ($ credentials as $ key => $ value ) {
182- $ this ->where ('LOWER( ' . $ this ->db ->protectIdentifiers ("users. {$ key }" ) . ') ' , strtolower ($ value ));
186+ $ this ->where (
187+ 'LOWER( ' . $ this ->db ->protectIdentifiers ("users. {$ key }" ) . ') ' ,
188+ strtolower ($ value )
189+ );
183190 }
184191
185- if (! empty ($ email )) {
186- $ data = $ this ->select ('users.*, auth_identities.secret as email, auth_identities.secret2 as password_hash ' )
192+ if ($ email !== null ) {
193+ $ data = $ this ->select (
194+ 'users.*, auth_identities.secret as email, auth_identities.secret2 as password_hash '
195+ )
187196 ->join ('auth_identities ' , 'auth_identities.user_id = users.id ' )
188197 ->where ('auth_identities.type ' , Session::ID_TYPE_EMAIL_PASSWORD )
189- ->where ('LOWER( ' . $ this ->db ->protectIdentifiers ('auth_identities.secret ' ) . ') ' , strtolower ($ email ))
198+ ->where (
199+ 'LOWER( ' . $ this ->db ->protectIdentifiers ('auth_identities.secret ' ) . ') ' ,
200+ strtolower ($ email )
201+ )
190202 ->asArray ()
191203 ->first ();
192204
Original file line number Diff line number Diff line change @@ -45,6 +45,22 @@ public function testSaveInsertUser(): void
4545 ]);
4646 }
4747
48+ /**
49+ * @see https://github.com/codeigniter4/shield/issues/546
50+ */
51+ public function testFindByCredentialsEmptyEmail (): void
52+ {
53+ $ users = $ this ->createUserModel ();
54+ $ user = $ this ->createNewUser ();
55+ $ users ->save ($ user );
56+
57+ $ user = $ users ->findByCredentials (['email ' => '' ]);
58+ $ this ->assertNull ($ user );
59+
60+ $ user = $ users ->findByCredentials ([]);
61+ $ this ->assertNull ($ user );
62+ }
63+
4864 public function testInsertUserObject (): void
4965 {
5066 $ users = $ this ->createUserModel ();
You can’t perform that action at this time.
0 commit comments