Frontend login by name

I’ve used the access restriction recipe for a frontend login solution and it works fine.

Now I wonder if I could fetch the user not by e-mail (username) but by the name, so I could use something like „Guest“ as a login name. I realize this could lead to problems since names are not unique, but I wonder if it’s possible.

I’ve unsuccessfully tried to change the controller to:

if ($user = $kirby->user()->username(get('loginname'))) {}

if ($user = $kirby->user('email@gmail.com')->username(get('loginname'))) {}

Thanks for help!

Uh, didn’t find that, thanks!