vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB3 General Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=111)
-   -   Transfer user data from one vB to another (https://vborg.vbsupport.ru/showthread.php?t=60731)

rikman 01-25-2004 05:56 PM

Transfer user data from one vB to another
 
1 Attachment(s)
We want to start a second board and want to give the users the option to transfer their user data (from vB's table 'user') to our new board.

I got the following idea:

- get username, password, salt and email from the user table
- encrypt these and transfer to the new server
- decrypt data and insert into the other user table (if username or email isn't used already)
- tell the user, that his account has cloned and that he should update his profile/options

Transfer works fine, inserting into database too, but if I want to log in, vB gives me a redirect page that says "Thanks for logging in ...". After that the forum is shown right to left?! (Look at the screeshot that is attached)

Has anybody an idea what went wrong? Are there important settings I've ignored?

Logging in with normal created (vB's registration procedure) user names works fine.

This ist the script that the user runs (source server):

PHP Code:

<?PHP
/////////////////////////////////////////////////////////////////////////
//
// register_rrnews.php
//
// transfer of user data from one user table to another
//
// Marcus T. Jaschen <m@rikman.net>
// 2004-01-22
//
// Version 0.0.1 (alpha)
//
/////////////////////////////////////////////////////////////////////////

// debug mode and error reporting
error_reporting (E_ALL);
define ("DEBUG"true);

// constants
//     key for XOR encryption
define ("XORKEY""dskjfwjeltkcjhsfkdhgsdjkhgwrkytiwreygiwyr95t435tgkhfs,"); // only an example
//    remote script
define ("REMOTESCRIPT""http://www2.sampleserver.com/user_xfer/userdata_xfer_vb.php");

// other scripts
chdir ("../forum/");
require (
"global.php");
chdir ("../user_xfer/");
require (
"../tool/mysql.class.php");
require (
"../tool/page.class.php");

//////////////////////////////////////////////////////////////////////////

// create new HTML page
$p = new Page ("Userdaten transferieren nach rennrad-news.de");
$p->addHeader ();
$p->addH1 ("Userdaten transferieren nach rennrad-news.de");

if (
DEBUG) {
    
$p->addP ("<font color=\"red\">Debug-Modus aktiviert!</font>");
    
$p->addNewline ();
}

// get UserID from vB login information
$intUserID $bbuserinfo['userid'];

// get required user data from user table
$dbUser = new mysql ();
$dbUser->query ("SELECT username, password, email,salt FROM user WHERE userid = ".$intUserID);
$r $dbUser->next ();

$strPlainUsername $r['username'];
$strPlainPassword $r['password'];
$strPlainEmail $r['email'];
$strPlainSalt $r['salt'];

$dbUser->close ();

// print username
$p->addP ("Deine Userdaten (<b>" $strPlainUsername "</b>) werden nach rennrad-news.de uebertragen ...");
$p->addP ("Userdaten aus Datenbank holen ...");

if (
DEBUG) {
    
$p->addDebug ("<b>Aus DB geholte Daten:</b>");
    
$p->addDebug ("Username (Plain): <b>" $strPlainUsername "</b>");
    
$p->addDebug ("Password (Plain): <b>" $strPlainPassword "</b>");
    
$p->addDebug ("EMail (Plain):<b>" $strPlainEmail "</b>");
    
$p->addDebug ("Salt (Plain):<b>" $strPlainSalt "</b>");
}

// encrypt user data
$strEncryptedUsername $strPlainUsername XORKEY;
$strEncryptedPassword $strPlainPassword XORKEY;
$strEncryptedEmail $strPlainEmail XORKEY;
$strEncryptedSalt $strPlainSalt XORKEY;

if (
DEBUG) {
    
$p->addDebug ("Username (XOR): <b>" $strEncryptedUsername "</b>");
    
$p->addDebug ("Password (XOR): <b>" $strEncryptedPassword "</b>");
    
$p->addDebug ("EMail: (XOR)<b>" $strEncryptedEmail "</b>");
    
$p->addDebug ("Salt: (XOR)<b>" $strEncryptedSalt "</b>");
}

// Base64 encryption (for URL)
$strEncryptedUsernameBase64 base64_encode ($strEncryptedUsername);
$strEncryptedPasswordBase64 base64_encode ($strEncryptedPassword);
$strEncryptedEmailBase64 base64_encode ($strEncryptedEmail);
$strEncryptedSaltBase64 base64_encode ($strEncryptedSalt);

if (
DEBUG) {
    
$p->addDebug ("Username (Base64): <b>" $strEncryptedUsernameBase64 "</b>");
    
$p->addDebug ("Password (Base64): <b>" $strEncryptedPasswordBase64 "</b>");
    
$p->addDebug ("Email (Base64): <b>" $strEncryptedEmailBase64 "</b>");
    
$p->addDebug ("Salt (Base64): <b>" $strEncryptedSaltBase64 "</b>");
}

// create hash
$strHash md5 ($strPlainUsername $strPlainPassword $strPlainEmail $strPlainSalt);

if (
DEBUG) {
    
$p->addDebug ("MD5 Hash der Userdaten: <b>" $strHash "</b>");
}

// status message for user
$p->addP ("Userdaten verschluesseln ...");

// generate URL
$strScriptURL REMOTESCRIPT;
$strScriptURL .= "?u=" $strEncryptedUsernameBase64;
$strScriptURL .= "&p=" $strEncryptedPasswordBase64;
$strScriptURL .= "&e=" $strEncryptedEmailBase64;
$strScriptURL .= "&s=" $strEncryptedSaltBase64;
$strScriptURL .= "&h=" $strHash;

if (
DEBUG) {
    
$p->addDebug ("Skript URL auf Remote Server: <b>" $strScriptURL "</b>");
}

// status message for user
$p->addP ("Userdaten uebertragen ...");
$p->get ();

// call script at remote server

require ($strScriptURL);

$p->clear ();
$p->addP ("&lt;EOF&gt;");
$p->addFooter ();
$p->get ();
exit ();

?>

... and this the script that is included (resides on the destination server):

PHP Code:

<?PHP
/////////////////////////////////////////////////////////////////////////
//
// userdata_xfer.php
//
// Inserts user data into vB-Database/table 'user'
//
// Marcus T. Jaschen <m@rikman.net>
// 2004-01-22
//
// Version 0.0.1 (alpha)
//
//////////////////////////////////////////////////////////////////////////

// Debug mode and error reporting
error_reporting (E_ALL);
define ("DEBUG"true);

// constants
//     Key for XOR Encryption
define ("XORKEY""dskjfwjeltkcjhsfkdhgsdjkhgwrkytiwreygiwyr95t435tgkhfs,"); // only an example

// other scripts
require ("../tool/mysql.class.php");

// collecting output of this script
$strOut "";

//////////////////////////////////////////////////////////////////////////

if (DEBUG) {
    print (
"<p><font color=\"red\">Debug-Modus in userdata_xfer.php aktiviert!</font></p>\n");
    print (
"<p>&nbsp;</p>");
}

// status message for user
print ("<p>Datenuebertragung nach rennrad-news.de abgeschlossen ...</p>\n");

// status message for user
print ("<p>Daten wieder entschluesseln ...</p>\n");

// get URL parameters
$strEncryptedUsernameBase64 $_GET['u'];
$strEncryptedPasswordBase64 $_GET['p'];
$strEncryptedEmailBase64 $_GET['e'];
$strEncryptedSaltBase64 $_GET['s'];
$strHash $_GET['h'];

if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Username (Base64): <b>" 
$strEncryptedUsernameBase64 "</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Password (Base64): <b>" 
$strEncryptedPasswordBase64 "</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> EMail (Base64): <b>" $strEncryptedEmailBase64 
"</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Salt (Base64): <b>" $strEncryptedSaltBase64 
"</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> MD5 Hash: <b>" $strHash "</b></p>\n");
}

// Base64 decode

$strEncryptedUsername base64_decode ($strEncryptedUsernameBase64);
$strEncryptedPassword base64_decode ($strEncryptedPasswordBase64);
$strEncryptedEmail base64_decode ($strEncryptedEmailBase64);
$strEncryptedSalt base64_decode ($strEncryptedSaltBase64);

if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Username (XOR): <b>" $strEncryptedUsername 
"</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Password (XOR): <b>" $strEncryptedPassword 
"</b></p>\n");
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> EMail (XOR): <b>" $strEncryptedEmail "</b></p>
\n"
);
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Salt (XOR): <b>" $strEncryptedSalt "</b></p>
\n"
);
}

// XOR decryption

$strPlainUsername $strEncryptedUsername XORKEY;
$strPlainPassword $strEncryptedPassword XORKEY;
$strPlainEmail $strEncryptedEmail XORKEY;
$strPlainSalt $strEncryptedSalt XORKEY;

if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Username (Plain): <b>" $strPlainUsername "</b>
</p>\n"
);
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Password (Plain): <b>" $strPlainPassword "</b>
</p>\n"
);
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> EMail (Plain): <b>" $strPlainEmail "</b></p>
\n"
);
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Salt (Plain): <b>" $strPlainSalt "</b></p>
\n"
);
}

// compare hashes and exit if fails

$strHash2 md5 ($strPlainUsername $strPlainPassword $strPlainEmail $strPlainSalt);

if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> MD5 Hash: <b>" $strHash2 "</b></p>\n");
}
if (
$strHash != $strHash2) {
    print (
"<p><font color=\"red\">Fehler bei der Datenuebertragung. Userdaten nicht konsistent! Skript beendet.</font>
</p>\n"
);
    exit ();
}

// status message for user
print ("<p>Daten auf rennrad-news.de importieren ...</p>\n");

// check for existing username/email
$dbUser = new mysql ();
$strQuery "SELECT count(*) FROM user WHERE username = '" $strPlainUsername "' OR email = '" $strPlainEmail 
"'";
if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> Username/Email frei? SQL Query: <b>" $strQuery 
"</b></p>");
}
$dbUser->query ($strQuery);
$r $dbUser->next ();

if (
$r[0] > 0) {
    
// error message
    
print ("<p><font color=\"red\">Username/Emailadresse auf rennrad-news.de bereits vergeben! Kann Import nicht 

fortsetzen.</font></p>"
);
    exit ();
} else {
    print (
"<p>Username/Email auf rennrad-news.de noch nicht vergeben ... alles ok.</p>\n");
}

// write user data into user table
$intDate time ();
$strQuery "INSERT INTO user (username, password, email, usergroupid, joindate, salt) VALUES ('" 
$strPlainUsername "','" $strPlainPassword "','" $strPlainEmail "', 2, $intDate, '" $strPlainSalt "')";

if (
DEBUG) {
    print (
"<p><font color=\"red\">DEBUG (userdata_xfer.php):</font> SQL Query: <b>" $strQuery "</b></p>");
}

$dbUser->query ($strQuery);

$dbUser->close ();

print (
"<p>Daten importiert.</p>");
print (
"<p>Bitte unter <a href=\"http://www.rennrad-news.de/forum/\">rennrad-news.de</a> mit deinen mtb-news.de 
Userdaten anmelden und dein Profil sowie deine Optionen eingeben, da diese Daten nicht mit transferiert wurden.</p>
\n"
);
?>

Many thanks, rikman

Apophis 02-12-2004 02:54 PM

I get that same result when adding a user to a vb3 database via an external 3rd party application. I've not yet found an answer as to why the forums display in a reverse order yet though.

Andreas 02-12-2004 03:41 PM

I think it's a problem with languages.
Check all your installed languages that text-direction is set Left to Right

Apophis 02-12-2004 06:03 PM

Okay.. I've been playing with this for hours today and I found the solution to having the forums displaying their content backwards.

When you create a new record in the users table, you also need to create new empty records in the userfield and usertextfield tables. If you have empty records with the proper userid in both of those two tables the account will log in properly.

At least that worked for me..


All times are GMT. The time now is 02:42 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.03079 seconds
  • Memory Usage 1,838KB
  • 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
  • (2)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