Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Temporary Solution: Importing Customer Password from outside

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 06-28-2005, 02:03 PM
  Caue's Avatar 
Caue Caue is offline
 

Advanced Member
  
Join Date: Apr 2005
Location: Brazil - USA
Posts: 34
 

Default Temporary Solution: Importing Customer Password from outside

I was writing this "little" post to try to obtain help to solve this problem that I was having on importing passwords from plain to encrypted with xcart text_crypt function.

After 2 days working on this (and at same time doing lot of other stuffs) I finally got to a kinda obvious solution...
If at least I had someone who could understand what I were doing and would point me "why don't you just do [this]" it would have been done at least 24hours ago.

"[this]" means "moving the same function I were using to encrypt with text_crypt function from my PHP personalized script to admin/user_modify.php".
That solved all my problems on this importing.

The script is included in the "little" post above. I hope this solution can get head aches out of a lot of people out there.
In fact, it just needed to go into a better place than in this topic that I'm just creating to share it.

This is my first return to this community. I couldn't get much help out of it yet, but I'll keep on trying. :P

Remember, while the code included in here will work alone, you should remove the function and add it to admin/user_modify.php to actually get the text_crypt working properly
All you have to do is having a pre-prepared table with username and passwords, or just modify the code that's not that complicated.

I didn't get to any other better solution and I don't have the time to keep trying and get to know how the text_crypt works in reality.
Also I saw that some warning came up when I did it, but as I already spended way too much time in this, I didn't even read them. This is just temporary anyway.


---------------------------------
References:
http://forum.x-cart.com/viewtopic.php?t=10740 -nice 27stars script
http://forum.x-cart.com/viewtopic.php?p=95925 -guy with same problem

Those are kinda old and inactive references.

I'm pretty sure I got something wrong on using the text_crypt function, I can't tell what.
Also I don't know if there's anything else that could be wrong.

So basically, I'm asking for a script, just like 27stars one, but one that works. :P


Now, here was my problem... Read it if you are curious or maybe it can help who is ceptic about me to get to know me a little better.
I'm just telling that because I have the feeling like I never have got a good straight answer, neither from psoft support, neither in this forum.
I believe it's because I'm giving wrong information out, or missing something. I must be doing something wrong.

[don't need to read]
---------------------------------
I got a list of customers with plain text user and password, among other information.

This other table, of course, don't have all the same information, so some customization needed to be done to import the data. Of course this potentially could have bring problems.

I still don't know what field is needed and what relation might be missing with another table. But I did added a customer, it looks to me that the only table that register.php works with is the xcart_customers, and then I checked the fields on how they are arranged before trying to bring the "outsider table" information into xcart.

I have made similar rows on xcart_costumers, but the login still doesn't work. I'm using the text_crypt function just like on 27stars's script. I even used the text_decrypt function to show (to myself) that the password is actually being properly encrpyted. There is no secret on the script, but if you need to see it, I'll copy it in here:
P.S. I like to make it as a function so it is easier to "comment out".
Code:
execute(); function execute () { //Only included file really needed would be "include/func.php", but the following is done because func.php can't be just simply included @include_once "top.inc.php"; include_once $xcart_dir."/config.php"; include $xcart_dir.DIR_CUSTOMER."/referer.php"; // this seens to not be needed //Just connecting to the database $mylink = @mysql_connect($sql_host, $sql_user, $sql_password); if (!$mylink) die("error_connect=".$sql_host); else if (!@mysql_select_db($sql_db)) die("error_select_db=".$sql_db); else { import_passwords(); } if ($mylink) @mysql_close ($mylink); } function import_passwords () { $qs = "SELECT login, password FROM temp_xcart_customers"; // this is a previous imported table, as the name sugest $res = mysql_query($qs) or die("<pre>\nQuery Failed: \n $qs \n Error: \n " . mysql_error() . "\n</pre>"); echo "<table border=\"1\" width=\"500\">\n"; $count = 0; while ($line = mysql_fetch_array($res)) { $count++; $user = addslashes($line["login"]); $passwd = $line["password"]; $crypted = addslashes(text_crypt($passwd)); //just like it is on register.php $uncrypted = text_decrypt(stripslashes($crypted)); //for debugging purpose $qs = "UPDATE xcart_customers SET password = '$crypted' WHERE login = '$user'"; mysql_query($qs) or die("<pre>\nQuery Failed: \n $qs \n Error: \n " . mysql_error() . "\n</pre>"); echo "<tr><td>$merchant_password</td><td>$count</td><td>$user</td><td>$passwd</td><td><pre>$crypted</pre></td><td>$uncrypted</td></tr>\n"; } echo "</table>\n"; echo "<h3>finished</h3>"; //this is more usefull than it looks }

Once the data is in xcart_customers, I can see all information (except the password, of course) in the administration panel, searching for each user. I know that this wouldn't work without the usertype, as it shows on 27stars's script. Also, if I look at the source in there, the password is written in it (which shouldn't be done that way) and it is wrongly decrypted.

Also, looking into the xcart database, the imported rows and the rows made by xcart itself contain way too diferent pattern passwords. While Xcart's customer's password looks like "Shjadjhklajrlke" (this is random input) the imported customer's password look like this:
"S????e6637?? a ma
J??bWц╗?7u
"
I mean, one has only letters, the other one has any kind of ASCII code.

And at last I tried to just copy a password from a row from XCart to imported row and the login works.
---------------------------------
[/don't need to read]
__________________
-- 2005-10 (signature needing update)
X-Cart Gold 4.0.13 [win] -- developing purpose
(migrating to [rhel3 as] some day)
Reply With Quote
  #2  
Old 11-07-2005, 07:27 AM
 
skipmartin skipmartin is offline
 

Advanced Member
  
Join Date: Oct 2003
Posts: 30
 

Default THANK YOU!

I used this to successfully import 675 customers from an old Interchange customer database. You saved me many, MANY hours of trying to figure this out. THANKS!
__________________
Andy Melichar, Tech Director - REBEL INTERACTIVE -
andy@rebel-interactive.com - X-Cart version 4.1.3
Reply With Quote
  #3  
Old 11-16-2005, 06:55 AM
  Caue's Avatar 
Caue Caue is offline
 

Advanced Member
  
Join Date: Apr 2005
Location: Brazil - USA
Posts: 34
 

Default

Thanks for your feedback!

I'm glad to know at least one person could benefit from it.
__________________
-- 2005-10 (signature needing update)
X-Cart Gold 4.0.13 [win] -- developing purpose
(migrating to [rhel3 as] some day)
Reply With Quote
  #4  
Old 01-16-2006, 01:06 PM
 
HawkCode HawkCode is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 30
 

Default

I hope you see this.

I'm new to PHP programming and was wondering where to put this in the user_modify.php.

Also you mean just the 2 functions correct?

Thanks
__________________
xCart Version 4.0.17

Richard S Albrecht
Reply With Quote
  #5  
Old 01-17-2006, 05:55 AM
  Caue's Avatar 
Caue Caue is offline
 

Advanced Member
  
Join Date: Apr 2005
Location: Brazil - USA
Posts: 34
 

Default sorry I can't help any further right now

That's a very good question, it's something I should have mentioned.

I don't remember where I've put it, but I do remember the results came in the top.

I probably put it as first things right after any INCLUDE or REQUIRE, where I'd naturally think it's the first proper place to add the line.

But, right now, out of any further testing / retrying, I'd say you can put in the first line of user_modify.php

At same time, I'm not sure if one can use this little work-around without knowing some scripting... But if that's all you need to know, there you go.


Now, the following is a little bit irrelevant. But since you said you're new to PHP:
In fact, the functions itself could be anywhere in any file within the chain of inclusion, but better keep it simple and put them together with the one line that starts the functions, and that's the one line you should care about where to put in: execute();
__________________
-- 2005-10 (signature needing update)
X-Cart Gold 4.0.13 [win] -- developing purpose
(migrating to [rhel3 as] some day)
Reply With Quote
  #6  
Old 01-17-2006, 06:42 AM
 
HawkCode HawkCode is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 30
 

Default

Thanks for the reply. I am a programmer and have written a PHP script to take a CSV and import to a MySQL database on our web sever.

I am basically a Delphi, VB .Net programmer so I'm not totaly new. I will probally start working on this next week.

Is it OK if I run into a problem to post some questions here?

Thanks
__________________
xCart Version 4.0.17

Richard S Albrecht
Reply With Quote
  #7  
Old 01-17-2006, 07:09 AM
  Caue's Avatar 
Caue Caue is offline
 

Advanced Member
  
Join Date: Apr 2005
Location: Brazil - USA
Posts: 34
 

Default anytime

Sure, that's what the forums are meant for, I suppose.

People helping people.

I just miss a forum more "wikable"...
Reply With Quote
  #8  
Old 01-19-2006, 11:25 AM
 
HawkCode HawkCode is offline
 

Advanced Member
  
Join Date: Jan 2006
Posts: 30
 

Default

Alright I need help.

Firest Here is my import script:

Code:
function execute () { //Only included file really needed would be "include/func.php", but the following is done because func.php can't be just simply included include $xcart_dir."include/func.php"; @include_once "top.inc.php"; //include_once $xcart_dir."/config.php"; //include $xcart_dir.DIR_CUSTOMER."/referer.php"; // this seens to not be needed //Database details $sql_hostname = 'localhost'; $sql_user = 'user; $sql_password = 'password'; $mambo_database_name = 'dbname'; $mambodb = mysql_connect($sql_hostname, $sql_user, $sql_password) or die ('Connection not possible : ' . mysql_error()); echo" ----------------------------------- "; echo" Connected to the database in" ; echo" ------------------------------------ "; print(" $sql_hostname"); mysql_select_db($mambo_database_name, $mambodb) or die ('Can not find database ' .$mambo_database_name . ': ' . mysql_error()); import_passwords(); } function import_passwords () { $path_to_csv = 'impxcart.csv'; $csv_delimiter = ","; echo "<table border=\"1\" width=\"500\">\n"; $count = 0; echo "About to open:".$path_to_csv; $handle = fopen ($path_to_csv,"r"); $Cnt = 0; $CharsToRemove = array(" ", "-", "'", "."); while (($data = fgetcsv ($handle, 1000, $csv_delimiter)) !== FALSE) { $login = mysql_escape_string($data[0]); str_replace($CharsToRemove, "", $login); $usertype = $data[1]; $Membership = mysql_escape_string($data[2]); $Password = addslashes(text_crypt($data[3])); $b_address = mysql_escape_string($data[4]); $b_city = mysql_escape_string($data[5]); $b_state = mysql_escape_string($data[6]); $b_zipcode = mysql_escape_string($data[7]); $Title = mysql_escape_string($data[8]); $FirstName = mysql_escape_string($data[9]); $LastName = mysql_escape_string($data[10]); $company = mysql_escape_string($data[11]); $s_address = mysql_escape_string($data[12]); $s_city = mysql_escape_string($data[13]); $s_state = mysql_escape_string($data[14]); $s_zipcode = mysql_escape_string($data[15]); $EMail = mysql_escape_string($data[16]); $Phone = mysql_escape_string($data[17]); $Fax = mysql_escape_string($data[18]); $count++; mysql_query("INSERT INTO xcart_customers(login, usertype, Membership, Password, b_address, b_city, b_state, b_zipcode, Title, FirstName, LastName, company, s_address, s_city, s_state, s_zipcode, EMail, Phone, Fax) VALUES('$login', '$usertype', '$Membership', '$Password', '$b_address', '$b_city', '$b_state', '$b_zipcode', '$Title', '$FirstName', '$LastName', '$company', '$s_address', '$s_city', '$s_state', '$s_zipcode', '$EMail', '$Phone', '$Fax')") or die(" Error doing insert:".mysql_error()); echo "<tr><td>$login</td><td>$data[0]</td><td>$LastName</td><td>$FirstName</td></tr>\n"; } echo "</table>\n"; echo "<h3>finished</h3>"; //this is more usefull than it looks fclose($handle); mysql_close($mambodb); }

I inserted this in user_modify.php right after the

Code:
require "./auth.php"; require $xcart_dir."/include/security.php"; define('USER_MODIFY', 1);

I uploaded my csv to same admin directory

then created a file to call the execute called RunImport.php

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> </head> <body> <?php include 'user_modify.php'; execute(); ?> </body> </html>

Now when I load RunImport.php I get this error from xcart:

Warning: Smarty error: unable to read resource: "partner/main/register.tpl" in /var/www/aspe.org/htdocs/xcart/Smarty-2.6.9/Smarty.class.php on line 1088

This is displayed on the Admin screen.

I did put it all in 1 file and it ran fine, however it didn't put the correct password in, same problem you originally had.

Any help would be appreciated.

TIA[/code]
__________________
xCart Version 4.0.17

Richard S Albrecht
Reply With Quote
  #9  
Old 01-30-2006, 08:57 AM
  B00MER's Avatar 
B00MER B00MER is offline
 

X-Guru
  
Join Date: Sep 2002
Location: Keller, TX (Cart-Lab.com)
Posts: 3,165
 

Default

Nice to see someones scripted an import customers script.

What I mainly do when importing a clients customer base over from an pre-existing 3rd party cart is get all the information into excel to fine tune and extract only the necessary needed data. If the passwords are plain text I use this simple tool I wrote awhile back:

http://www.cart-lab.com/lab/salt.php

And copy all the needed passwords in order into the text area, and convert the plain text passwords into a format I can copy/paste into my excel document and create a new CSV file which I then upload into the xcart_customers table via phpMyAdmin.

Kudos however on the code Caue, defiantly makes this whole process easier.
__________________
Cart-Lab - 100+ Social Bookmarks for X-Cart.
Reply With Quote
  #10  
Old 03-30-2006, 02:59 AM
  Caue's Avatar 
Caue Caue is offline
 

Advanced Member
  
Join Date: Apr 2005
Location: Brazil - USA
Posts: 34
 

Default

oh, sorry I couldn't answer before. I've had many things happening, and I had to quit my job where I used to handle x-cart. even my e-mail was configured within the company, otherwise I'd have answered you before HawkCode. next month I might get back some working on it, and that's why I came to check new stuff.

anyway, what's "Kudos", Boomer? It sounds like a name of something to me, but wikipedia says it's a regular word (that I've never heard of). o_O

heh, that's one reason why I mostly hate uppercases...

back to the subject, Hawk, I'm sorry I can't read your whole script and try to understand it right now, but I just noticed you're running 4.0.17 and I were running 4.0.13

i know for a fact that the problem i was having was a version issue, so it might have changed on your version and it would need some adaptation. now, i reall don't recall out of my head what you could do, but as soon as i get started with x-cart again i'll take a look into that.

although i hope you have everything solved by now, hopefuly not manualy. :P

-- caue.cm.rego@gmail.com
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions



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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 11:21 PM.

   

 
X-Cart forums © 2001-2020