Go Back   vb.org Archive > vBulletin 4 Discussion > vB4 Programming Discussions

Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2010, 05:34 PM
auctionguy auctionguy is offline
 
Join Date: Mar 2007
Location: USA
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default Manually adding user to database; Can't login with user

I am trying to make a little script to manually add a new user to the vbulletin database. I understand how the password hashing works and have made a script that shows me what should be in the password field when I put in whats in the salt field, so I know the user im manually adding has the right password accoridng to it's salt. For some reason I still can't login to vbulletin with this user I manually added. I tried password reset on the user and afterwards logging in worked with the new password. I assumed some field in db I missed was preventing the original from logging so I compared the user's db info before and after password reset, and other than the password and the salt, I saw no difference. So I am really stumped on what could be preventing the login.

Like I said, I looked at the salt for a working user, and did the md5(md5(password) . salt) and got whats in the password field, then did the same for the manually added user whom I can't login with and got what the password field said for both, so I know thats not the problem.

I am using the code for adding the admin user in the install portion of the script as a template for manually adding this user. The only thing I am doing differently is the options field. I am not puting any of the useroption defaults like vbasset_enable, showsignatures because I don't really know how to insert that. However, the user still is getting a string of numbers in the 'options' field in the database, however it isnt changing after the password reset so I don't even see how that could be the problem.

I am totally stumped on this, please help.
Reply With Quote
  #2  
Old 06-11-2010, 05:57 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

If you want coding help, the best thing to do is to post your exact code, let us know exactly where you are adding it, and then post your template, and let us know where it is being added.
Reply With Quote
  #3  
Old 06-11-2010, 06:00 PM
auctionguy auctionguy is offline
 
Join Date: Mar 2007
Location: USA
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Ok, this is just on a php file not in an vbulletin file.

PHP Code:
<?php

//CONNECT TO DB
mysql_connect(localhost,'######''#####');
@
mysql_select_db('######') or die( "Unable to select database");
define('TIMENOW'time());

//PASSWORD SALT GENERATION AND ENCRYPTION

function fetch_user_salt($length)
{
    
$salt '';
    for (
$i 0$i $length$i++)
        {
            
$salt .= chr(rand(33126));
        }
        return 
$salt;
}

$salt fetch_user_salt(3);

//INSERT INTO VBULLETIN DB

$username "Bill";
$pass md5('test1');
$email "test@test.com";
$salt md5($salt);
$newpass md5($pass $salt);

mysql_query("INSERT INTO user
                (username, salt, password, email, joindate, lastvisit, lastactivity, usergroupid, passworddate, showvbcode)
            VALUES (
                '" 
mysql_real_escape_string(htmlspecialchars($username)) . "',
                '" 
mysql_real_escape_string($salt) . "',
                '" 
mysql_real_escape_string(md5($pass $salt)) . "',
                '" 
mysql_real_escape_string($email) . "',
                " 
TIMENOW ",
                " 
TIMENOW ",
                " 
TIMENOW ",
                2,    FROM_UNIXTIME(" 
TIMENOW "), 1) ");

$userid mysql_insert_id();            
mysql_query("INSERT INTO usertextfield (userid) VALUES ($userid) ");
mysql_query("INSERT INTO userfield (userid) VALUES ($userid) ");
mysql_close();

?>
Reply With Quote
  #4  
Old 06-11-2010, 06:06 PM
Lynne's Avatar
Lynne Lynne is offline
 
Join Date: Sep 2004
Location: California/Idaho
Posts: 41,180
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

In vb4, salt is 30 characters, not 3:
PHP Code:
$salt fetch_user_salt(3); 
Change that to 30.
Reply With Quote
  #5  
Old 06-11-2010, 06:16 PM
auctionguy auctionguy is offline
 
Join Date: Mar 2007
Location: USA
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Changed it. Didn't fix the problem. I put 3 because in vb when it makes the admin account in install it used 3. Either way, I have the same problem though.
Reply With Quote
  #6  
Old 06-11-2010, 06:19 PM
NBZ4live NBZ4live is offline
 
Join Date: Jun 2010
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

The best way to add new account to vBulletin is to use the vB_Datamanager_User.
Here is the code I use in my Integration.

PHP Code:
function add_new_vb_user($data){
    global 
$vbulletin;
    
    
$userdata =& datamanager_init('User'$vbulletinERRTYPE_ARRAY);
    
$userdata->set('email'$data['email']);
    
$userdata->set('username'$data['username']);
    
$userdata->set('password'$data['password']);
    
$userdata->set('usergroupid'$data['usergroupid']);
    if(isset(
$data['membergroupids'])) $userdata->set('membergroupids'$data['membergroupids']);
    
$userdata->set('ipaddress'IPADDRESS);
    
$userdata->set('showbirthday'0);
    
$userdata->set('timezoneoffset'1);
    
$userdata->set_usertitle(''false$vbulletin->usergroupcache[$data['usergroupid']], falsefalse);
    
$userdata->pre_save();
    
    if (!empty(
$userdata->errors))
    {
        return 
false;
    }else{
        
$vbulletin->userinfo['userid']
        = 
$userid
        
$userdata->save();
        
        return 
true;
    }

Try include global.php to your script and then use this function to create the accounts.
Reply With Quote
  #7  
Old 06-11-2010, 06:50 PM
auctionguy auctionguy is offline
 
Join Date: Mar 2007
Location: USA
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Worked beautifully! Thank you so much for sharing your code with me. I guess I was just taking the wrong approach to this by trying to force the db entry rather than work with the vb code.

I have one more problem, and this may be a dumb question. I want this code to not be in the /forum directory but in the root directory of my site. If I include the global.php file, it includes /includes/class_bootstrap.php. Since my original file is not in the same directory as the global.php, the address to class_bootstrap isn't correct for my original file and I get a cannot find file error. I looked in some of the vb files to see how they solved this problem, and I see that they use this format when in this situation:

PHP Code:
require_once(DIR '/includes/XXXX.php'); 
Using this "DIR" does not work on my file outside of the forum directory, as I assumed. How can I do the same thing but with my file outside of the forum directory?
Reply With Quote
  #8  
Old 06-11-2010, 11:10 PM
NBZ4live NBZ4live is offline
 
Join Date: Jun 2010
Posts: 5
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Use
PHP Code:
chdir("forum/"); 
before including global.php

Here is the description: chdir

after using the Datamanager to add the user you can change the directory back with
PHP Code:
chdir(".."); 
Reply With Quote
  #9  
Old 06-11-2010, 11:58 PM
consolegaming consolegaming is offline
 
Join Date: Jan 2007
Posts: 168
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Quote:
Originally Posted by NBZ4live View Post
The best way to add new account to vBulletin is to use the vB_Datamanager_User.
Here is the code I use in my Integration.

Try include global.php to your script and then use this function to create the accounts.
My problem with that solution (and why I often opted for the manual solution whenever I needed to do something like this ) is that if a user is temporarily suspended from the forums they are blocked from any pages that include global.php. Obviously for this exact thing it's not an issue as they won't even be registered at this point. But more for things like PM creations, checking your user is logged in (checking sessions same way as vb does and updating last activity etc), and other similar things like that.

Or at least that's the result I got when I tested this a few years ago. And that was an unacceptable condition for our website. Banned for life members I would agree with. But we still wanted people that were suspended (for things like spamming etc ) to still be able to use the rest of our website. We saw the website and forums separate in that sense. Just seemed so strange to me that it forced it on you. Unless there's a way to stop that which I'm not aware of, or if they've changed how that works since I tested it a few years ago. I'd much prefer to use Vb's own functions/data managers as it's a bit messy doing things yourself.
Reply With Quote
  #10  
Old 06-12-2010, 03:38 AM
auctionguy auctionguy is offline
 
Join Date: Mar 2007
Location: USA
Posts: 127
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Well the script I'm trying to integrate with vb is not letting me include global.php. Every time I try I get some error that says ajax must be enabled. So I guess I'm going to have to stick with the manual route. That being said, I still don't know why my original code didn't work correctly. Consolegaming can you either tell me what is wrong with my code or give me a sample of how you are manually inserting users to vb database? I would be very appreciative.
Reply With Quote
Reply

Thread Tools
Display Modes

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 02:53 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.04842 seconds
  • Memory Usage 2,293KB
  • Queries Executed 13 (?)
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
  • (6)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)navbar
  • (3)navbar_link
  • (120)option
  • (1)pagenav
  • (1)pagenav_curpage
  • (1)pagenav_pagelink
  • (10)post_thanks_box
  • (10)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (10)post_thanks_postbit_info
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)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_postinfo_query
  • fetch_postinfo
  • 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
  • pagenav_page
  • pagenav_complete
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete