Answers.Body: <p>A possible workaround would be to use the phone numbers <em>as</em> the username.</p>
  
  <p>Then you could write a <a href="https://pluginfactory.io" rel="nofollow noreferrer">Craft plugin</a> that listened to the <a href="https://craftcms.com/docs/plugins/events-reference#userSession-onBeforeLogin" rel="nofollow noreferrer">onBeforeLogin</a> event and validated the entered phonenumber against your custom field and proceeded accordingly.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-19T18:39:37.637Z
Answers.LastActivityDate: 2017-04-19T18:39:37.637Z
Answers.UserDisplayName: Brad Bell
Answers.Body: <p>The short answer is no. Craft does not natively support this, and there's no way to implement it via a hook (or event).</p>
  
  <p>A quick browse through the code shows that <a href="https://craftcms.com/classreference/etc/users/UserIdentity#authenticate-detail" rel="nofollow noreferrer">the <code>UserIdentity::authenticate</code> method</a> is where most of the action takes place (called from <a href="https://craftcms.com/classreference/services/UserSessionService#login-detail" rel="nofollow noreferrer">the <code>UserSessionService::login</code> method</a>), and that's very much tied to using either a username or an email address.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2017-04-19T14:21:27.847Z
Answers.LastActivityDate: 2017-04-19T14:21:27.847Z
Answers.UserDisplayName: Stephen Lewis
Body: <p>I added a field called "phonenumber" to the user profile fields which I want to use for login purposes, too.</p>
  
  <p>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.</p>
  
Tags: <users><login><user-profile><custom-field><authentication>
Title: Authentication by a custom field
ThreadText: # Authentication by a custom field
  
  (Asked by: username_0 on 2017-04-19)
  
  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.
  
  **Tags:** users, login, user-profile, custom-field, authentication
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2017-04-19. Score: 1
  
  A possible workaround would be to use the phone numbers *as* the username.
  
  Then you could write a [Craft plugin](https://pluginfactory.io) that listened to the [onBeforeLogin](https://craftcms.com/docs/plugins/events-reference#userSession-onBeforeLogin) event and validated the entered phonenumber against your custom field and proceeded accordingly.
  
  
  ---
  
  ### Answer by username_2 on 2017-04-19. Score: 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](https://craftcms.com/classreference/etc/users/UserIdentity#authenticate-detail) is where most of the action takes place (called from [the `UserSessionService::login` method](https://craftcms.com/classreference/services/UserSessionService#login-detail)), 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.
  
  
  ---
  
  