News:

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

Main Menu

Link users to custom database

Started by Cheaterman, July 02, 2014, 05:21:18 PM

Previous topic - Next topic

Cheaterman

Hi and thanks in advance for your support,

I'd like to create custom fields for user profile (which if possible would also be available at registration time), simply a username and a password that I would validate against my custom database.

I'll then need to persist this relationship, in order to fetch user data later on from my custom database.

The use case is fairly simple: I own a game server. My users create accounts on the forums, and I'd like to link these accounts with their ingame accounts, then display some of the linked data in profile view page and probably also when an user posts, below its avatar.

So the idea is that I'd create a table, joining forum account IDs with ingame logins, and this table will only get filled when the user successfully adds a character through the login/password screen that I want to create on profile/registration.

So far I have no clue how to achieve this, I'm digging in Profile.php to create a new action linking to my custom PHP file, but I'd prefer making it custom "profile fields" - however searching these keywords on Google points me to the mod, which is obviously not sufficient for what I need.

Thanks in advance for any help you will provide!

Illori

you want your users to enter a username and password they use for something else into a plain text field? that sounds like a security nightmare.

Cheaterman

The password would obviously be in a password-type input :) other than that yeah, it will be transmitted as plain-text since my forum isn't served over SSL. I'm not really worried about security though (let's say I have a consistent background in the field), more about following SMF's coding guidelines as well as I can (except that I'm gonna use PDO for dealing with my DB) and finding out what file I'll have to edit.

So far, I found out that I should edit Profile-Modify.php to add the field itself and its validation function (that is, the function that will check the credentials against my DB), and Load.php (function loadMemberData()) to load the appropriate data in my member context from my custom join table in SMF DB ($select_tables and $select_columns). I will then edit the appropriate template file(s) to display that data.

Seems correct?

Illori

and the password is then sitting in your database in plain text, it is also available to all admin of your forum...

Cheaterman

#4
Nope it's not.

Apparently you don't understand how to implement such system in a secured way, so let's recap:

The user types in username/password on his profile, password being a password-type input (obviously). The validation function checks the credentials against my accounts database. If the validation returns true, a new record will be added to a (previously created) join table with two fields: member_id (from SMF), and account_id (from my accounting system). Then accounts are linked, and no security issue.

Would you have tips on how (where?) to implement such a system inside SMF please? Thanks for your concerns about safety but as I mentioned I'm quite aware of the ins and outs of web application security.

Illori

you know sending me an email will not help you get a reply any faster. for that matter it will guarantee that you will not get further replies from me even if i knew the solution to your problem.

Cheaterman

No problems :) you have had you three attempts, now let others try as well! ^__^

So far I found out (thanks to a nice person on IRC) I should edit Profile-Modify.php to add my custom fields and their custom validation function and Load.php to load the data from the join table - which should then be available in my $memberContext for display in my profile template.

Ninja ZX-10RR

Nope you do this like that dude, I am a developer as well and we really made the thing you are attempting to do. It will be *way* easier to just link the in-game profiles with the forum ones.
I will link you a very special topic I have created.. It's special to me as it was my first topic in this forum --> http://www.simplemachines.org/community/index.php?topic=520741.msg3684367#msg3684367, I will never thank Margarett enough for that answer.
Basically you need to link the usernames and the passwords. Linking the usernames is easy you just need to link the function to call the usernames but the passwords are much harder as they are sha1 encrypted. That's why I linked you that topic.
As this whole thing was done by my colleague and me in cooperation I can't guarantee that I will be answering immediately if you have further problems but I hope that topic will help you because I can assure you that it helped me a lot at that time.
You will be then creating another table next to the username that will be the in-game nickname (that you may want to differ from the forum username) and the game should have both the permissions to write in that table and also to read from there but remember that the login system must be based on the forum username :)
Hope this helps :) gg (pretty sure you will know what these 2 letters mean) ;)
Quote from: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Cheaterman

Thanks a lot for your answer! What you achieved is great too, however I need the ability to link multiple characters to a single forum account, so I proceeded as stated above, simply using the validation callback of the name field to validate the name/password pair against my custom DB. I didn't realize I had to convert characters to ASCII manually in PHP (as opposite to C) which caused some issues with my hashing functions but it all ended up working properly.

I will now proceed to editing the templates & models in order to fetch my custom data and display it where I want, as well as adding an extra boolean field to my join table in order to set one character as "main".

Thanks again for your help!

Ninja ZX-10RR

You're welcome man ;)
Thanks to margarett for pointing me that way in the first place and sorry for the late reply (week in hospital).
Quote from: BeastMode topic=525177.msg3720020#msg3720020
It's so powerful that on this post and even in the two PMs you sent me,you still answered my question very quickly and you're apologizing for the delay. You're the #1 support I've probably ever encountered man, so much respect for that. Thank you, and get better soon.

I'll keep this in my siggy for a while just to remind me that someone appreciated what I did while others didn't.

♥ Jess ♥

STOP EDITING MY PROFILE

Advertisement: