4

I'd like to bulk register users without email address in my component. Afaik there isn't a database constraint, so in theory it is possible to inject the rows necessary to do this. I'd rather use the JUser class if it is possible to do the same with that. What I need from it is password hashing and username generation from the real name. Any experience with that?

  • try this - stackoverflow.com/a/34921238/3114661 – Joomler Feb 15 '17 at 18:01
  • @Joomler What happens with your code when you pass an empty email? ... – inf3rno Feb 15 '17 at 18:07
  • email is required, if email is empty then it wont add the user. – Joomler Feb 15 '17 at 18:51
  • 1
    @Joomler Ye, that's the problem this question is about... – inf3rno Feb 15 '17 at 19:37
2

Okay, I found the solution for password encryption: https://stackoverflow.com/questions/21304038/joomla-3-2-1-password-encryption

jimport('joomla.user.helper');
$yourpass = JUserHelper::hashPassword($password_choose);

So I just hash the password and insert the row to the users table with empty email. Adding them to some groups is just as easy by adding rows to the user_usergroup_map table. If you want the users to be able to login, you need to add them at least to the registered user group. I generated a dummy email address too, something like {username}.dummy@host just to be sure, but this solution does not send out annoying registration emails.

  • 2
    I think you are a better off to insert a dummy email for each user lest you keep hitting email required warnings if you ever try to edit the user in the backend for example. Something like: random_string_here@yourowndomain.com and as long as your domain's catchall is configured to discard all email then that should be fine. – jamesgarrett Feb 15 '17 at 21:25
  • @jamesgarrett Thanks James! Email is not important in this scenario. I just need around 150 users to be able to login and use a relative simple component. – inf3rno Feb 15 '17 at 21:42
  • @jamesgarrett Should I add a formally valid email, like {username}@xxx.com to avoid errors? – inf3rno Feb 15 '17 at 21:48
  • i don't think it matters if the email account exists or not if that is what you are asking. So {username}@xxx.com or dkf93tkos0ekfku3@xxx.com are both suitable dummy email addresses to use. I should add to be clear, if it is not obvious, that I suggesting that you generate a unique random string for each user. – jamesgarrett Feb 15 '17 at 23:36
  • @jamesgarrett I thought I just leave it empty, but okay adding a non-existent email address of the same domain cannot hurt. Is there a way to reuse the text -> dash/underscore case transformation in joomla? For example it is used by converting article titles to uris. – inf3rno Feb 16 '17 at 8:20

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.