View Single Post
  #4  
Old 08-29-2011, 07:56 PM
35mm 35mm is offline
 
Join Date: Jul 2010
Posts: 18
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Hi Ingwa, my site is not in production yet so I changed the password hashing of the site to use the same hashing method of vb. I also sync the user ID's from both systems. So when a user signs up or changes their password, it also creates/updates their forum account. As the main site also has user profiles and messenger, I didn't want vb user profiles or messenger so re-routed those to the main site's. I also got rid of vb's register page and login.

Now when a user logs into the main site, they are automatically logged into vb too. This is just simply a question of creating the sessions/cookies that vb's login process creates.

I think this is my working code - based on someone else's code example from some other thread here;
PHP Code:
// vBulletin logins
                    
$vbuser "SELECT salt FROM vb_user WHERE userid = '$userID' LIMIT 1";
                    
// add query call here....

                    
if(mysql_num_rows(query) == 1){
                        
$vbsalt mysql_result(query,0,'salt');
                    }
                    
$cookie_salt "xxxxxxxxxxxxxx"// cookie salt - from /forum/inc/functions.php line 30 ish
                    
$cookie_password_salted md5($pass.$cookie_salt);
                    
// grab user's IP here (we called it $alt_ip)
                    
$vbidhash md5($_SERVER['HTTP_USER_AGENT'].$alt_ip); // not too smart using unpurified &_SERVER var there tut tut
                    
$vbsessionhash md5(uniqid(microtime(), true));
                    
mysql_query("DELETE FROM `vb_session` WHERE `userid`='$userID' OR `host`='$ip'",$dbconnect); // delete old session
                    
mysql_query("INSERT INTO `vb_session` (`sessionhash`, `userid`, `host`, `idhash`, `lastactivity`, `location`, `useragent`, `styleid`, `languageid`, `loggedin`, `inforum`, `inthread`, `incalendar`, `badlocation`, `bypass`, `profileupdate`) VALUES ('$vbsessionhash', '$userID', '$alt_ip', '$vbidhash', '$session_time', '$url_path/forums/', '$new_useragent', '0', '0', '2', '0', '0', '0', '0', '0', '0')",$dbconnect);
                    
setcookie('bb_lastvisit',$session_time,$cookie_expire,$url_path.'/',$site_domain); 
                    
setcookie('bb_lastactivity',0,$cookie_expire,$url_path.'/',$site_domain); 
                    
setcookie('bb_sessionhash',$vbsessionhash,$cookie_expire,$url_path.'/',$site_domain); 
                    
setcookie('bb_userid',$userID,$cookie_expire,$url_path.'/',$site_domain); 
                    
setcookie('bb_password',$cookie_password_salted,$cookie_expire,$url_path.'/',$site_domain);
                    
// 
Some obvious things have been removed from the code, but it should give you an idea of the process and what needs to be done.

Some considerations;
You are probably better off giving your vb users the same user id as they have in your main user db, rather than using the auto increment in the vb user table.

For ease of integration I would suggest you use vb's password hashing method for password hashing in your main user database so that their passwords in both databases are the same - have the same hashed result.

In your process for users to change or reset their passwords on your main site, make sure you add code so it also updates their password in vb user table.

Redirect all vb registration requests, login and lost password requests etc to your main site registration, login and password reset etc pages.

I hope this helps!
Reply With Quote
 
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.02432 seconds
  • Memory Usage 1,798KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD_SHOWPOST
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)bbcode_php
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_box
  • (1)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (1)post_thanks_postbit_info
  • (1)postbit
  • (1)postbit_onlinestatus
  • (1)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • reputationlevel
  • showthread
Included Files:
  • ./showpost.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showpost_start
  • bbcode_fetch_tags
  • bbcode_create
  • postbit_factory
  • showpost_post
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • showpost_complete