Having my custom registration page insert data into user table


Active member
Hey guys,

What I'm trying to do here is have my custom registration form insert data into the XF database. The only problem I having here is getting the password into the correct format. I've looked into the core.php file trying to figure out exactly what is going on here, but I'm still a bit confused.

My main questions are this:

The remember_key is the correct place to put the "password" correct?
Is there a function I can send the $password from my form to, and have it return the correct formatted password for insertion?

Everything else I seem to be alright with, just the darn password....

And if you're wondering, I will be maintaining two seprate databases, one for my site, and one for the forum, and keeping them in sync through my custom forms, and just running dual SQL statements.

Any input on this is greatly appreciated!



Well-known member
Is using a DataWriter not an option for you?

Using the user datawriter to create users properly would simplify your processing greatly
and make it a bit more forward compatible.


Active member
I have looked lightly at the datawriter user file when I was searching through everything.

I will go have another peek at it and try to come up with a more specific question to help you help me figure this out :)

Thanks for your input. I didn't know the datawriter was what I needed to be working with here.


Active member
Alright, after looking through the file, I think it will do exactly what I need.

I hate to be so oblivious, but I have no idea how to pass my data to this.

I have all of the checks on my registration form, so if I can just pass it the few fields I have, and have rest defaulted that would be perfect.

Can I just (in theory) include the users.php datawriter and then call the functions in my script somehow?


Well-known member
1. Initialize the xenforo framework in your script.
2. Create an instance of the user datawriter, using XenForo_DataWriter::create('XenForo_DataWriter_User')
3. Set the fields using the set() method
4. Call pre-save methods
5. Grab the errors, if any; otherwise save()

Look at how the registration controller does that; in XenForo_ControllerPublic_Register
lines 110 to 186, specifically.


Active member
Wow, thanks for the great post!

I'll go through all of this and see what I can get working.

One more quick question. Is the "remember_key" field in xf_user_authenticate technically the "password"?


Well-known member
The remember "key", I believe, is used for processing the automatic logins for returning users.
(ie, the "Remember Me" stuff)


Active member
So where is the actual password stored? I have been unable to find it.

I'm just having a bad night...I cant find out how to initialize the framework...
I'm really not the type of person to ask someone to do everything for me....but there should really be a doc on how to load it in your page....and I thought there was but I can't find it...

Can I ask you kindly to point me in the right direction there?

After that point the rest of it appears to make sense.


Well-known member
(you can skip the last line, which initializes the session)

Also, the hashed password is stored in a serialized array in xf_user_authenticate.data, along with other data used for authenticating a user. What's stored in that array depends upon the authentication scheme you are using. For vBulletin, only "salt" and "hash" are stored; while for core xenforo auth: "salt", "hash" and "hash function" are stored.


Active member
Alright well thanks to all of your help, I have successfully got an implementation working in my forum.

The next step is logging in. I would like to have my login form set dual cookies/sessions, so that both "scripts" (xenforo and my system) will recognize the users as logged in.

I poked through the Login.php file and Session.php file. I'm just unsure on how to continue.

I know I will need to start by calling the framework, and then calling the class for login. I guess my real question here is what type of format can I use to pass the required variables to the XenForo_ControllerPublic_Login function?
I could not find a direct cookie-setting command within this function, but just thinking on common sense here I'm assuming that it is tied into that function somehow.

And Shadab, thanks again for your help :D


Well-known member
Once you've initialized the xf framework + session objects, and done your own page processing; you'll have to call the changeUserId() method for the session object to change the logged-in user:

Untested, as usual:
// Change the logged in user to the one with user_id of $userId

// If you just want to login the user, and not use anything else from xf in your script;
// you can skip this line.

Adrian Mester

New member
I can't seem to get changeUserId to work. Shouldn't the following code in a file login the user with user_id = 1?

$startTime = microtime(true);
$fileDir = dirname(__FILE__);

require($fileDir . '/library/XenForo/Autoloader.php');
XenForo_Autoloader::getInstance()->setupAutoloader($fileDir . '/library');

XenForo_Application::initialize($fileDir . '/library', $fileDir);
XenForo_Application::set('page_start_time', $startTime);

(Without startPublicSession I get a "An unexpected error occurred. Please try again later." error.)

Am i missing something?


Well-known member
Once you are done making any changes to the session object, call the save() method on it;
to persist those changes via cookies/database.

$session = XenForo_Session::startPublicSession();

$visitor = XenForo_Visitor::setup(1);