Hi,

This sounds very complicated for me, I hope it does not. Can I use this module and the provided Phone field as a replacement to the username? I want my user to create accounts and then log-in with using their phone numbers as their usernames; with the proper validations like the formatting and uniqueness etc etc etc

Thanks...

Comments

cweagans’s picture

Category: support » feature

I suppose you could sort of do this if you want, but it would require some custom code.

Basically, you'll want to do this:

- add a phone field to user entities
- form alter the username field away
- add a validate function to the user form that takes the value of the phone number field, then does a form_set_value into the username field

This will make all new users have a phone number as a username (and also in the phone number field). When they go to login, they'll just use that phone number. I would recommend stripping all non-numeric characters from the phone number before saving it as the username.

This does bring up an interesting question: would it be worthwhile to add a submodule that supports this? I can't think of very many cases where the username should be a phone number, but the Phone module seems like a logical place to put that functionality. Let me think about it.

hgurol’s picture

Well, a potential client, we are talking about migrating his custom build ecommerce site to drupal. His current site is built that way and he says it is a must for him if he ever decides to move to drupal.

The way I look at it, unless you send text messages to the number to verify the new accounts, it is not that much appealing. I can very well add the phone field to user entity, make it appear on registration form and make it a required field(i guess). For me this is good enough but not good enough for my potential client.

I dont know, there might be more use cases that this functionality would become handy and I sure would be very happy if you decide to add that option to the module.

If you decide not to do it and if I decide to go for it myself; do I really need to deal with the validation myself. I thought this modules own validation will take care of it for me. No?

Thanks for taking the time Cameron.

cweagans’s picture

Well, there's a couple of things happening there. The validate callback is to take the phone number value and insert it into the username field so that users can authenticate with their phone number.

The validation of the actual phone number is handled by this module, and the user module would validate that it is a unique number/username.

I'm saying that you should put the phone field on the user registration form and hide the username field. The validate handler populates the username field with the value from the phone field.

nevets’s picture

I think it would be easier to add custom validation on the existing user name field.

cdale’s picture

I think this would be better handled by an even more generic solution rather than in phone itself. Something that allows any field, or combination of fields on the user entity to be used as the "username". That module would then handle validation etc... This would also make it very simple to have email as a username, phone, country, numbers only.. etc... Not sure if such a module exists, but could be something worthwhile.