Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 General Discussions
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools Display Modes
  #1  
Old 06-08-2010, 04:04 AM
30et 30et is offline
 
Join Date: Mar 2009
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default external login - logouthash

Hi there

I have created a simple script that is a login form for vbulletin 4.

I was using the variables available when including global.php but this didn't work on some of my pages as I couldn't set the include directory since it was already set by another CMS system. eg chdir($_SERVER['DOCUMENT_ROOT'] . '/forums');

So instead I manually connected to the vb database and got the session and user details. The only thing I can't get is the logouthash variable.

logouthash is defined in the /includes/functions.php -
PHP Code:
    $user['securitytoken_raw'] = sha1($user['userid'] . sha1($user['salt']) . sha1(COOKIE_SALT));
    
$user['securitytoken'] = TIMENOW '-' sha1(TIMENOW $user['securitytoken_raw']);

    
$user['logouthash'] =& $user['securitytoken']; 
I can get the userid and salt from the database and I can define COOKIE_SALT myself to match whats in /includes/functions.php but the variable that is difficult is TIMENOW.

Is TIMENOW the same as time()?

I find if I echo TIMENOW its not the same as time() and it changes all the time?

How should I define TIMENOW or is there a better way to do this whole thing?
Reply With Quote
  #2  
Old 06-08-2010, 04:21 AM
ForumsMods ForumsMods is offline
 
Join Date: Aug 2007
Location: Argentina
Posts: 667
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

You are right. TIMENOW is time()
PHP Code:
define('TIMENOW'time()); 
Reply With Quote
  #3  
Old 06-08-2010, 05:04 AM
30et 30et is offline
 
Join Date: Mar 2009
Posts: 13
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Thanks for that. I got it working. Here is the code in case it can help others -
PHP Code:
// connect to db
include $_SERVER['DOCUMENT_ROOT'] . '/forums/includes/config.php';
$DB_SERVER = $config['MasterServer']['servername']; ///mysql server
$DB_LOGIN =  $config['MasterServer']['username']; /// Database Login - You have to give login name for DB
$DB_PASSWORD = $config['MasterServer']['password']; /// Database Password
$DB_DATABASE = $config['Database']['dbname']; ////Database name
$DB_PREFIX = $config['Database']['tableprefix'];
$vip_con=mysql_connect ($DB_SERVER, $DB_LOGIN, $DB_PASSWORD) or die ('Cannot connect to the database.');
mysql_select_db ($DB_DATABASE);

// get if logged in from db
$vip_sql = "SELECT s.loggedin, u.username, u.userid, u.salt FROM " . $DB_PREFIX .  "session s INNER JOIN " . $DB_PREFIX .  "user u ON s.userid = u.userid WHERE sessionhash = '" . $_COOKIE['bb_sessionhash'] . "'"  ;
$vip_result = mysql_query($vip_sql) or die ('query not working'.mysql_error());
$row = mysql_fetch_array( $vip_result );
$vip_loggedin = $row['loggedin'];
$vip_username = $row['username'];
$TIMENOW = time();
$vip_cookie_salt = 'Cc26QdsovANkeY3pRPt36wERQP'; // this is copied from forums/includes/functions.php
 
// create logouthash 
$vip_securitytoken_raw = sha1($row['userid'] . sha1($row['salt']) . sha1($vip_cookie_salt));
$vip_securitytoken = $TIMENOW . '-' . sha1($TIMENOW . $vip_securitytoken_raw);

$vip_logouthash =& $vip_securitytoken;

// close db connection
mysql_close($vip_con);



if ($vip_loggedin!=0) {
?>
<p>You're logged in as <b><?php  echo $vip_username?></b></p>
<a class="more_info" href="/forums/login.php?<?php echo $session[sessionurl]; ?>do=logout&amp;logouthash=<?php echo $vip_logouthash?>">Log Out</a>
--------------- Added [DATE]1275978418[/DATE] at [TIME]1275978418[/TIME] ---------------

Oh yeah I should mention if you've got other db connections open you might need to do this to seperate the vb db connection.
Change
PHP Code:
$vip_con=mysql_connect ($DB_SERVER$DB_LOGIN$DB_PASSWORD) or die ('Cannot connect to the database.');
mysql_select_db ($DB_DATABASE); 
to
PHP Code:
$vip_con=mysql_connect ($DB_SERVER$DB_LOGIN$DB_PASSWORDtrue) or die ('Cannot connect to the database.');
mysql_select_db ($DB_DATABASE$vip_con); 
Reply With Quote
  #4  
Old 01-20-2011, 06:53 AM
brandondrury brandondrury is offline
 
Join Date: Oct 2005
Posts: 136
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Works great, dude! Thanks. You saved me a days work trying to figure out the login code myself.

Just for corrections sake, I did have to add this to bottom to complete the final if statement:

PHP Code:
<?php ?>
Now I just need to figure out how to snag the user variables I need from the database. I guess I can do it the old-fashioned way, but I was really hoping that good ol' this would work:

PHP Code:
$userid=$vbulletin->userinfo['userid'];
$usergroup=$vbulletin->userinfo['usergroupid'];
$membergroupids$vbulletin->userinfo['membergroupids']; 
The jury is still out.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:31 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.03645 seconds
  • Memory Usage 2,204KB
  • Queries Executed 11 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (1)ad_showthread_firstpost
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (7)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (4)post_thanks_box
  • (4)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (4)post_thanks_postbit_info
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.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_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • 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
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete