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

Reply
 
Thread Tools Display Modes
  #1  
Old 11-14-2009, 11:08 PM
WeBBy WeBBy is offline
 
Join Date: Jun 2003
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Automatically login to vbb

I have a site that is controlled by a user class and that vbb is only a part of the site structure. What I need is for when the person logs into the main site, they automatically get logged-in to vbb.

They are registered automatically into vbb from the main user class (direct db input). The vbb registration is disabled -> the user being redirected to the user class login.

What I have now is a global vbb plugin which detects whether the user is logged in with the user class, and if yes, I extract their username/password from the database and the vbb login (hidden) is automatically filled in.

I then have autologin with another plugin using javascript as
Code:
<? if ($memuser !=''){
echo "<script type=\"text/javascript\" language=\"JavaScript\">
<!--
document.mylogin.submit();
//--></script>";
} ?>
There has to be a better way of automatically having the user logged in upon entering vbb and/or upon logging in with the user class.

Any suggestions would be greatly appreciated. Thanx
Reply With Quote
  #2  
Old 11-17-2009, 12:50 PM
WeBBy WeBBy is offline
 
Join Date: Jun 2003
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Nevermind, figured out how to do it...

Stripped the login function from login.php and renamed it vbblogin.php and then added it to the user class I am using from the main site. Needed a few minor modifications to the vbb login, but got it working.

When someone logs-in from any external page, they are logged in to the userclass as well as vbb all in one login request.

Thanks anyway
Reply With Quote
  #3  
Old 11-17-2009, 06:28 PM
ChopSuey ChopSuey is offline
 
Join Date: Jun 2009
Location: Alaska
Posts: 2,140
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Wow, nice! Don't mind sharing?
Reply With Quote
  #4  
Old 11-17-2009, 07:13 PM
WeBBy WeBBy is offline
 
Join Date: Jun 2003
Posts: 43
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want to know how....

I use a access_user_class on several sites because it is readily customizable and offers a high degree of security (http://www.finalwebsites.com/snippets.php?id=10).

1. As part of the registration for the general user-class login, I added an automatic vbb account as follows:

Code:
 //Create Randon Salt 4 password
	function gen_salt($length = '3')
    {
    $salt = "";
    $possible = "abcdefghjklmnpqrstuvwxyzABCDEFGHJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+=[]{}\/.,?<>~";
    $i = 0;
    while($i < $length)
        {
        $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
        $salt .= $char;
        $i++;
        }

    return $salt;
    }  
//generate encrypted password
	$mysalt = gen_salt();
	$vbbpasswd = md5(md5($_POST[password]).$mysalt);
//Add to vbb user table
$db = mysql_connect("localhost", "username", "userpass") or die ("Cannot connect to MySQL");
mysql_select_db("dbname",$db) or die ('Cannot Connect to Forum Database');
$query = "insert into user (usergroupid, username, password, email, usertitle, ipaddress, salt) values ('2', '$_POST[username]',  '$vbbpasswd',  '$_POST[email]',  'Title',  '$ip', '$mysalt')";
$result = mysql_query($query,$db) or die ("Cannot update Discussion Forum Database");
VBB User Account Created

2. Stripped out the login from vbb login.php and saved it as vbblogin.php:

Code:
<?
// ############################### start vbb login ###############################

$curdir = getcwd ();
chdir('/path/to/forum');
$_POST[vb_login_username] = $_GET[user];
$_POST[vb_login_password] = $_GET[mempass];
$_POST[cookieuser] = "1";

require_once('/path/to/forum/global.php');
require_once('/path/to/forum/includes/functions_login.php');
	$vbulletin->input->clean_array_gpc('p', array(
		'vb_login_username'        => TYPE_STR,
		'vb_login_password'        => TYPE_STR,
		'vb_login_md5password'     => TYPE_STR,
		'vb_login_md5password_utf' => TYPE_STR,
		'postvars'                 => TYPE_BINARY,
		'cookieuser'               => TYPE_BOOL,
		'logintype'                => TYPE_STR,
		'cssprefs'                 => TYPE_STR,
	));
	// can the user login?
	$strikes = verify_strike_status($vbulletin->GPC['vb_login_username']);
	// make sure our user info stays as whoever we were (for example, we might be logged in via cookies already)
	$original_userinfo = $vbulletin->userinfo;
	if (!verify_authentication($vbulletin->GPC['vb_login_username'], $vbulletin->GPC['vb_login_password'], $vbulletin->GPC['vb_login_md5password'], $vbulletin->GPC['vb_login_md5password_utf'], $vbulletin->GPC['cookieuser'], true))
	{
		($hook = vBulletinHook::fetch_hook('login_failure')) ? eval($hook) : false;
		// check password
		exec_strike_user($vbulletin->userinfo['username']);
		$vbulletin->userinfo = $original_userinfo;
			}
	exec_unstrike_user($vbulletin->GPC['vb_login_username']);
	// create new session
	process_new_login($vbulletin->GPC['logintype'], $vbulletin->GPC['cookieuser'], $vbulletin->GPC['cssprefs']);
	// do redirect
	exec_header_redirect($vbulletin->options['forumhome'] . '.php');
?>
Notice the:
Code:
$_POST[vb_login_username] = $_GET[user];
$_POST[vb_login_password] = $_GET[mempass];
$_POST[cookieuser] = "1";
at the top of the page. Will explain that later.

3. Now to login, I located the login and cookie functions of the access_user_class.php that performn the login/cookie which happens to be the function set_user().

I tried an include, but the scripting in vbblogin.php and access_user_class.php were in conflict and to take the cheap and easy way out (easier than fixing the conflicts), I used a Location to drive the vbb login:

Code:
//define username-password of access_user_class
		$user = $this->user;
		$mempass = $this->user_pw;
//Send it to vbblogin as a GET
		header("Location: http://www.mysite.com/forum/mystuff/vbblogin.php?user=$user&mempass=$mempass");
Probably not the best way to do it, but it works and accomplishes what I wanted. Because I am now using a GET and vbb is using a POST, I redefined the POST values to the GET values. The $user and $mempass are from the user_class but could be replaced with the original post[] command in the login form

I also changed the login form in the narbar template to the user_class login, added the user_class to the top of headinclude, changed logout to the user_class (rather than vbb), added a few plug-ins to deal with a few issues.

As I said, probably not the best way, but it works and probably can be applicable to a host of different external registration/login schemes.

Hope it helps someone
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 11:10 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.04867 seconds
  • Memory Usage 2,196KB
  • 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
  • (5)bbcode_code
  • (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