News:

Wondering if this will always be free?  See why free is better.

Main Menu

Bulk user creation from csv file

Started by MultiformeIngegno, April 23, 2018, 11:23:44 AM

Previous topic - Next topic

MultiformeIngegno

Hello,
I am trying to generate a number of accounts with a set username/password through a csv file.

I used this, adapting the snippet posted here to the db changes in SMF 2.0/2.1:

<?php

$importfile 
"members.csv";
$escape ",";

require_once(
dirname(__FILE__) . '/Settings.php');

// we start the database connection
$db_connection mysql_connect($db_server$db_user$db_passwd);
$db mysql_select_db($db_name);
$import file($importfile);

//remove the first line (description of user data)
array_shift($import);

//now loop all lines and insert the members
foreach ($import as $lines
{
   
//explode the lines
   
$users explode($escape,$lines);
    
//generate the dateRegistered
   
$regdate mktime();

   
//Now insert the new user
   
mysql_query("
      INSERT IGNORE INTO 
{$db_prefix}members
         (member_name, id_group, real_name, passwd, date_registered, email_address)
      VALUES ('
$users[0]', '$users[4]', '$users[1]', '" password_hash(sha1(strtolower($users[0]) . $users[2]), PASSWORD_BCRYPT) . "','$regdate', '$users[3]')");
}
mysql_close($db_connection);
echo 
'IMPORT COMPLETE!';
?>


The rows are added to the database, but when I try to login as one of the users I am redirected to the reminder page (?action=reminder).

I believe this has to do with the fact that the 'salt' column is not populated..? Any ideas?

EDIT: The .csv file is structured as follows:

member_name real_name passwd email_address member_group
RockCiclopedia (wiki - forum), Tutta la storia del rock, scritta da voi ...
Rimanere aggiornati sul mondo della musica grazie al nuovo feed "RockCiclopedia Music News"!



landyvlad

Would this mean there is a way to
1. Export a copy of all usernames/passwords from a live 2.0 instance
2. Import those usernames/passwords to a 2.1 beta TEST forum ?
"Put as much effort into your question as you'd expect someone to give in an answer"

Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

Be the person your dog thinks you are.

Kindred

No...   install 2.0, reload the database in the test server and reset sett8ngs...the upgrade
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

GigaWatt

@landyvlad: No, I think they're encrypted in the database.
"This is really a generic concept about human thinking - when faced with large tasks we're naturally inclined to try to break them down into a bunch of smaller tasks that together make up the whole."

"A 500 error loosely translates to the webserver saying, "WTF?"..."

Arantor

Set $modSettings['enable_password_conversion'] to 1. Then you can use the old password hashing system and SMF will upgrade the passwords to the new one when users log in (and you don't need to set the password_salt either)

landyvlad

Ta Kindred.

So to elucidate on what I (ideally) want to do.

I have a SMF 2.1 beta test forum.  There are currently 7 people registered on that.
I'd like to get all members/passwords from my existing 2.0 production forum across to the 2.1 test one (so they can get used to 2.1 but don't all need to re-register there in order to do so).

So I gather I can't do this any way other than converting the database to 2.1 and that if I do so the existing 7 members on the beta forum will be lost?

And if I need to convert the database over, can I do that without having to bring over any of the mods / attachments etc? But keep the content I already have on the test forum?



Arantor - thanks but that doesn't make sense to me due to my lack of "having a clue" :)

"Put as much effort into your question as you'd expect someone to give in an answer"

Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

Be the person your dog thinks you are.

Kindred

no...   if you want to add stuff on top of what you already have then things become much more complicated and you will have to do some manual stuff in the database and the code....
Слaва
Украинi

Please do not PM, IM or Email me with support questions.  You will get better and faster responses in the support boards.  Thank you.

"Loki is not evil, although he is certainly not a force for good. Loki is... complicated."

landyvlad

Thanks mate.  I'll leave that well alone then.

-----

Is it possible to create a duplicate of my existing forum, without the mods or attachments (but retaining the database, mod data so I can reinstall, etc?)

Tips?

eg copy across, delete attachment folder contents, ...

In order to ensure no mistakes as far as screwing up the production database is concerned could I rename the database in the test forum and would repair settings then link it properly ?

(I hope those questions make sense...)
"Put as much effort into your question as you'd expect someone to give in an answer"

Please do not PM, IM or Email me with questions on astrophysics or theology.  You will get better and faster responses by asking homeless people in the street. Thank you.

Be the person your dog thinks you are.

shawnb61

Yes, they make perfect sense.

I would suggest doing this in two steps.   Step 1 is to make a standalone, working, 2.0 test copy of your production forum.  Once that works...  Step 2 is to upgrade your test forum to 2.1.     
Address the process rather than the outcome.  Then, the outcome becomes more likely.   - Fripp

Advertisement: