News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Database Insert No Longer working with RC2

Started by skyguyt, April 01, 2020, 01:17:36 PM

Previous topic - Next topic

skyguyt

Good Afternoon,

I had previously been using build 2.0.17 and had a code that injected a user's data into smf_members flawlessly. With the update to RC2, I can no longer get the feature to work and was hoping someone would be able to notice any error in coding that may need to change to make it work with RC2. I see that total members does go up, and the latest member function on the forum goes blank, so it seems as if it just does not like what is being put into the members portion. Thank you for the help!

    public static function forum_register($eventinfo)    {

        $id = PilotData::getPilotByEmail($eventinfo[2]['email']);
        $pid = PilotData::getPilotCode($eventinfo[2]['code'], $id->pilotid);
        $username = $pid.' '.$eventinfo[2]['firstname'].' '.$eventinfo[2]['lastname'];
        $password = sha1(strtolower($username . $eventinfo[2]['password1']));
        $salt = substr(md5(mt_rand()), 0, 4);
        $time = time();
        $email = $eventinfo[2]['email'];

            $query = "INSERT INTO smf_members (
                            member_name,
                            email_address,
                            passwd,
                            password_salt,
                            posts,
                            date_registered,
                            real_name,
                            pm_email_notify,
                            id_theme,
                            id_post_group
                            )
                    VALUES (
                        '$username',
                        '$email',
                        '$password',
                        '$salt',
                        '0',
                        '$time',
                        '$username',
                        '1',
                        '0',
                        '4'
                        )";

            DB::query($query);

            $query2 = "SELECT * FROM smf_members WHERE member_name = '$username'";

            $member = DB::get_row($query2);

            $query3 = "UPDATE smf_settings
                        SET value = (value + 1)
                        WHERE variable = 'totalMembers'
                        LIMIT 1";

            DB::query($query3);

            $query4 = "REPLACE INTO smf_settings (variable, value)
                            VALUES ('latestMember', '$member->id_member')";

            DB::query($query4);

            $query5 = "REPLACE INTO smf_settings (variable, value)
                            VALUES ('latestRealName', '$member->member_name')";

            DB::query($query5);
}

Suki

Hi, welcome to SMF, is there anything in either your error log or SMF's error log?

Theresa also a function that handles all logic when registering a new user: Subs-Members::registerMember()  just need to pass your parameters to it.

Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

skyguyt

Quote from: Suki on April 01, 2020, 01:37:13 PM
Hi, welcome to SMF, is there anything in either your error log or SMF's error log?

Theresa also a function that handles all logic when registering a new user: Subs-Members::registerMember()  just need to pass your parameters to it.

Thank you very much! I show no errors in the error log or SMF's error log either which is the weird part. Is there any place I could go to read up more on the new logic and see if I can figure out how to re-code that to make it work correctly?

Thanks!

Suki

I would recommend to use the function as it takes care of everything for you: https://support.simplemachines.org/function_db/index.php?action=view_function;id=594

If you don't want to use it, you can directly see how SMF's handle the registration inside that very same function.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

skyguyt

Quote from: Suki on April 01, 2020, 01:49:25 PM
I would recommend to use the function as it takes care of everything for you: https://support.simplemachines.org/function_db/index.php?action=view_function;id=594

If you don't want to use it, you can directly see how SMF's handle the registration inside that very same function.

Thank you! I should have specified more that I have updated it to 2.1 RC2. I didn't see that on the menu for the register function.

Suki

The same function does exists on SMF 2.1 RC2. Don't know what you mean with "I didn't see that on the menu for the register function."
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Kindred

I think he means that the function database has not been updated to list SMF 2.1 functions...
Сл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."

Suki

Oh!  but that particular function hasn't changed if I recall correctly, the only change I can think of is the new password salt and hashing stuff, perhps thats the issue.
Disclaimer: unless otherwise stated, all my posts are personal and does not represent any views or opinions held by Simple Machines.

Oldiesmann

The reason the function DB hasn't been updated for 2.1 is we were planning (at least at one time) to use the comments within the code in conjunction with a docblock parsing script to automatically generate documentation (less time consuming and allows users to generate their own documentation should they wish to do so).

I'm not sure how viable that option is these days unfortunately. I did generate sample docs with apiGen a while back (see http://oldiesmann.us/smfdocs) but that script doesn't work anymore (outdated dependency that isn't compatible with PHP 7.2...)
Michael Eshom
Christian Metal Fans

Bobby

Quote from: skyguyt on April 01, 2020, 01:17:36 PM
       ... $password = sha1(strtolower($username . $eventinfo[2]['password1']));
        $salt = substr(md5(mt_rand()), 0, 4);


Hello, I think SMF2.1 changed the way of password encryption. You could see more in Register.php, Subs-Auth.php (function hash_password, hash_salt...), Sub-Password.php (function password_hash..).
I'm not sure, just guess so! :)

Kindred

Сл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."

skyguyt

Quote from: Bobby on April 03, 2020, 02:02:55 PM
Quote from: skyguyt on April 01, 2020, 01:17:36 PM
       ... $password = sha1(strtolower($username . $eventinfo[2]['password1']));
        $salt = substr(md5(mt_rand()), 0, 4);


Hello, I think SMF2.1 changed the way of password encryption. You could see more in Register.php, Subs-Auth.php (function hash_password, hash_salt...), Sub-Password.php (function password_hash..).
I'm not sure, just guess so! :)

I think you figured out the issue! Now for trying to figure out how to get the code changed to work with the new way of encryption...

Advertisement: