vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=251)
-   -   external login - logouthash (https://vborg.vbsupport.ru/showthread.php?t=244189)

30et 06-08-2010 04:04 AM

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?

ForumsMods 06-08-2010 04:21 AM

You are right. TIMENOW is time()
PHP Code:

define('TIMENOW'time()); 


30et 06-08-2010 05:04 AM

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); 


brandondrury 01-20-2011 06:53 AM

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.


All times are GMT. The time now is 09:13 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.01350 seconds
  • Memory Usage 1,736KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (7)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.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/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.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
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete