1

I added a field called "phonenumber" to the user profile fields which I want to use for login purposes, too.

Usually Craft allows an authentication by username or email-address. Is there a way to add another field for authentication, e.g. the custom field phonenumber? The goal is to expand Craft to accept logins via username and email-address as well as the phonenumber.

1

The short answer is no. Craft does not natively support this, and there's no way to implement it via a hook (or event).

A quick browse through the code shows that the UserIdentity::authenticate method is where most of the action takes place (called from the UserSessionService::login method), and that's very much tied to using either a username or an email address.

Your only option is to implement a custom plugin, with its own controller endpoints, which handles login requests. You would then submit the login form to your plugin, rather than to Craft.

Such a plugin will, of course, need to follow all of the same security best practises as the current Craft "login" implementation, and be actively maintained in case any vulnerabilities come to light.

| improve this answer | |
1

A possible workaround would be to use the phone numbers as the username.

Then you could write a Craft plugin that listened to the onBeforeLogin event and validated the entered phonenumber against your custom field and proceeded accordingly.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.