View Single Post
  #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