MyBB Community Forums

Full Version: Create several hundred users automatically
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Hello everyone,
I am quite new to MyBB, but so far everything works fine and it is totaly amazing. So, a big thanks to everyone contributing to this great project.

I have a hole bunch of users (300+), needed to be created automatically at once. I have all relevant information in an excel-file (name, email, random generated password). What's the best way to create them automatically?
Don't understand me wrong, I am not looking for a 2-click solution, just something more comfortable than creating all 300+ manually.

Any help or hint is highly appreciated.


Best regards
I can make a quick script for you at a reasonable price. It can be done today even. PM me if interested.
You could try importing it through phpMyAdmin as a CSV file. It probably will require some tweaking so it is highly recommend you backup your mybb_users table before doing so (or make a copy of it elsewhere and import it there first as a test).

If you're any good with PHP you can write your own script to read in your CSV file line by line, and use a loop to insert each row into the database.
Hi,
thank you for your quick replies. I think importing the entire user-db via phpmyadmin is the best solution for me, since I have almost no php-experience.

So the right steps would be:

- create example user with presettings
- export this row from mybb_users
- use this row as preset for all users in database
- change UID/password/username/email (any other fields required to "individualize" a user [on system-level, not stuff like icq,jabber,location,etc]? should salt be empty or is there any correlation to the md5-hashed pw needed for an initial login?)
- save as cvs
- import into mybb_users and pray

Are there any pitfalls on this I should be aware of?

Thanks and best regards! =)
That won't work the way you think. Passwords will all be wrong. There is almost no way around it without using php to create the passwords from existing ones. Is the password md5 or plain text? If it's plain text that makes it easier but you still need to use php to hash/salt it.

I am leaving on vacation tomorrow so if you need this done sooner rather than later let me know. Good luck to you if you're taking this on yourself.
Hi,
thanks for your offer, but actually there is no urge on this project (have a nice vacation Wink. Passwords are in plain text. As far as I understand, I can create the md5 hashes directly with an extermal php-script (should be feasible with google) and just ignore the salt for the initial-password. As soon the user changes his initial-password, mybb scripts do the salting.
So I would get around this problem, right?
I am not completly unwilling to learn some php (or whatever is required to accomplish this). I just didn't have any in-depth experience with php so far.

Thanks and best regards


(Sorry if my English is hard to understand and full of mistakes, I am not a native speaker and really down with my nerves due to some other problems)
The password should be md5-hashed, and salt blank.
Your english is great. You should learn some basic php anyways.

My advice...look into loops like foreach.
You can use this (untested) script as a base:
<?php

define('IN_MYBB', 1);
require './global.php';
require MYBB_ROOT."inc/datahandlers/user.php";

/************** CHANGE THE FOLLOWING FILENAME *******************/
$contents = file('mycsv.csv');
/****************************************************************/




foreach($contents as $line)
{
	$line = explode(',', str_replace(array("\n", "\r"), '', $line));
	
	
	$userhandler = new UserDataHandler("insert");
	$user = array(
	
	
	
	
/************** ADD USER FIELDS HERE *******************/
		'username'	=> $line[0],
		'password'	=> $line[1],
		'email'		=> $line[2],
		//... etc ...
/********************************************************/



	);
	$userhandler->set_data($user);
	if(!$userhandler->validate_user())
	{
		$error = $userhandler->get_friendly_errors();
		echo "<p style='color: red;'>Error inserting a user: $error<br />User: ";
		var_dump($user);
		echo "</p>";
	}
	else
	{
		$user_info = $userhandler->insert_user();
		echo "<p>User {$user_info['username']} inserted.</p>";
	}
}

echo "<p>Everything complete!</p>";
?>
You'll need to edit the filename to point to the correct file.
Also, you'll need to define the fields.

For example, in the above:
		'username'	=> $line[0],
		'password'	=> $line[1],
		'email'		=> $line[2],
Basically means that the first field in each line of the CSV file contains the username (field "0" - note that computers start with 0, not 1), the password is in field "1" etc. Change it to reflect your CSV structure.
Nice work. But here are some notes (also for future users of this script):

- Use set_time_limit(0) to extend the maximum allowed execution time (some servers have this pretty short)
- Using the user datahandler is a good method for small imports, but if you are trying to import more than a thousand at a time, I'd recommend directly inserting the user into the database instead of going through the datahandler.
Pages: 1 2