MyBB Community Forums

Full Version: Use my own username database for MyBB Logins?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Sorry if this is in the wrong place, I tried asking in the plugins section a little while back but had no luck. I'm just looking for an answer to see if this is possible:

I have a php website that already has a login system (username + hashed password stored in database).

I would like to add a forums section to my site, but I don't want my users to have to create another account... within their account... just to access the forums.

Is it possible to make MyBB access the already stored usernames, and grant access to the forum, assigning the user the same username they used to log into my site?

In other words, if I log into my site as the user "CoolCat123", I want to access the MyBB forums section as "CoolCat123
" (without being prompted to log in a second time).

Thanks all!
Hi there,

I think the best way to do this would be to - for the most part - leave the MyBB code alone, and implement all of the cross-site login/account stuff via the code for your existing site.

The main consideration I have for doing it this way is that you have control over your own code, whereas the MyBB code is largely out of your control, and implementing your intended features via MyBB plugins would - in my admittedly relatively ignorant assessment - be challenging and messy.

The next consideration given this approach is that MyBB stores user preferences in its user table, and references the ID of users in that table in multiple places (such as the post and thread tables, to track who wrote what), so that you will need to have a corresponding (duplicate) entry in your MyBB user table for each entry in your existing site's user table.

Given all of this, I would recommend this approach:

  1. Write and run a script to generate corresponding MyBB users (in the MyBB users database table) for your existing site's users.
  2. Extend your existing site's account-creation code so that from then on, whenever a new user account is created/edited, it automatically creates/updates a corresponding entry in the MyBB users table.
  3. Extend your existing site's login code so that whenever a user logs in (or out), an appropriate entry is created/updated/deleted in the MyBB sessions table, so that MyBB "sees" its corresponding user as logged in. Similarly for your logout code.
  4. Extend other aspects of your existing site's code as necessary/applicable - e.g., you might have code to ban/delete users, which you would need to extend to then perform the relevant and necessary updates on the MyBB database so that MyBB, too, sees the same (corresponding) user as banned/deleted/etc.

You would also need to set to "Yes" the "Disable Registrations" option in the "Login and Registration Options" settings page in your MyBB Admin Control Panel, so that new members are forced to register on your existing site.

Finally, you would need to decide whether or not you wanted to allow your members to also be able to log in (and out) from MyBB as well as from your existing site.

If you did want to support this, then you would probably want to write a little MyBB plugin that hooks in to, perhaps (I haven't looked closely into this) the "member_login" or, perhaps even better, "member_login_end" hook in /member.php (or similar), and, on successful login, update whatever tables it is necessary to update on your existing site so that it, too, "sees" your member as logged in there. Similarly for logging out.

If you did not want to support this, then you would similarly probably want to write a plugin to block access to those MyBB functions, and probably you would also need make edits to templates to remove the login elements of the MyBB user interface.

Those are my initial thoughts, in any case. Would be interested to know what others think.

Cheers.

Laird

P.S. An addendum: similarly for the login/logout functionality of MyBB, you would want to decide whether you want to support the banning/deleting/etc of users from MyBB (as well as from your existing site), and similarly you would then need to either suppress that functionality via a MyBB plugin or extend it via a MyBB plugin so that it performs the necessary changes/updates/deletions for the corresponding user in the database for your existing site.

P.P.S. After all that: a perhaps more efficient possibility is to migrate all of your existing site's user-related data to the MyBB user-related tables, and to update that code in your existing site which references your existing site's user-related tables to instead refer to the MyBB user-related tables to which you have migrated the data (you could then delete the original tables for your existing site). That would get around the hassle of having to duplicate users. The MyBB users table could easily be extended to have additional columns for any data specific to your existing site. Whether this approach was feasible would depend on the extent to which your existing site references its user table from other tables, and how easy it would be to migrate those references to refer instead to the MyBB users table.