Forums / All Other Contributions/Addons / Is a Permanent Login (Auto-Login) Possible?

Is a Permanent Login (Auto-Login) Possible?

Results 1 to 20 of 219
09 Feb 2007, 12:06
#1
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Is a Permanent Login (Auto-Login) Possible?

hey,

how could it be possible to let users "stay logged in on this computer" (auto / permanent login)?

thx
11 Feb 2007, 20:27
#2
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Sure, you just need to set a cookie, and configure the Zen Cart login to look for it.

http://us2.php.net/manual/en/features.cookies.php

Then take a look at...
  • [STORE_ROOT]/includes/modules/pages/login/header.php
  • [STORE_ROOT]/includes/modules/create_account.php
13 Feb 2007, 16:05
#3
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

okay, that works really nice.
but since it's so easy to modify cookies, how to make it safe?
store the password as md5-string in the cookie?
14 Feb 2007, 03:48
#4
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

The cookie should definitely have the PW encoded.
14 Feb 2007, 13:11
#5
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

sorry, but WHY wouldn't you take md5-encryption for the customers password?

zen_validate_password doesn't help any, because that function deals with the unencrypted password as value.
in the cookie i have an md5... and the function zen_encrypt_password always produces a different string...

how would you suggest to compare the md5-pw to the one in the db?
14 Feb 2007, 13:14
#6
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

sorry, my mistake.

of course i can store the password from the db in the cookie and have not to deal with this extendet encryption method :P
14 Feb 2007, 15:59
#7
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

Is this explained (i.e. a step-by-step how-to with code examples) anywhere for people like me - non-programmers but willing to have ago?
17 Feb 2007, 00:04
#8
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

I'll rephrase that - does anyone have a step-by-step guide as how to incorporate this in ZC? Or better still, a contribution? :wink2:
17 Feb 2007, 22:46
#9
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

okay, i'll write a brief explanation of that.
but tomorrow... :P
18 Feb 2007, 11:59
#10
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

hi.
  1. first of all, add a checkbox to your login-form called something like "permLogin".
    _
  2. edit the file "/includes/modules/pages/login/header_php.php"
    if the login is ok, zencart will proceed to the beyond line 57 and does all the stuff around line 70. just after this we hook in. put that code there:
    _
    if (!empty($_REQUEST["permLogin"])) {
    ___ unset($c);
    ___ $c[] = $_SESSION['customer_id'];
    ___ $c[] = $_SESSION['customer_default_address_id'];
    ___ $c[] = $_SESSION['customers_authorization'];
    ___ $c[] = $_SESSION['customer_first_name'];
    ___ $c[] = $_SESSION['customer_last_name'];
    ___ $c[] = $_SESSION['customer_country_id'];
    ___ $c[] = $_SESSION['customer_zone_id'];
    ___ $c[] = $check_customer->fields['customers_password'];

    ___ $c_str = implode("~~~", $c);
    ___ setcookie("zencart_cookie_permlogin", $c_str, time()+36000000);
    }
    ___
    this will store all the relevant information in the cookie.
    ___
  3. edit the file "/includes/modules/pages/index/header_php.php"
    if you start your zencart, this page will be loaded. here we check if the login is set and if, then we login automatically.
    at the very top of that file, just after "$zco_notifier..." add this code:
    ___
    if (substr_count($_COOKIE["zencart_cookie_permlogin"], "~~~") > 1) {
    ___ if (empty($_SESSION['customer_id'])) {
    ______ $c = explode("~~~", $_COOKIE["zencart_cookie_permlogin"]);

    ______ $q = "SELECT customers_password FROM " . TABLE_CUSTOMERS . " WHERE customers_id=" . $c[0];
    ______ $r = $db->Execute($q);

    ______ $pw_cookie = zen_db_prepare_input($c[7]);
    ______ $pw_zencart = $r->fields['customers_password'];

    ______ if ($pw_cookie == $pw_zencart) {
    _________ $_SESSION['customer_id'] = $c[0];
    _________ $_SESSION['customer_default_address_id'] = $c[1];
    _________ $_SESSION['customers_authorization'] = $c[2];
    _________ $_SESSION['customer_first_name'] = $c[3];
    _________ $_SESSION['customer_last_name'] = $c[4];
    _________ $_SESSION['customer_country_id'] = $c[5];
    _________ $_SESSION['customer_zone_id'] = $c[6];
    _________ $_SESSION['cart']->restore_contents();
    ______ }
    ___ }
    }
___
___
Thats pretty much it
:smile:
18 Feb 2007, 12:08
#11
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

Thankyou - much appreciated.
19 Feb 2007, 20:04
#12
pdprenty avatar

pdprenty

New Zenner

Join Date:
Sep 2006
Posts:
58
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Ok, I have done a few searches, but I couldn't find anything definitive.


add a checkbox to your login-form called something like "permLogin".



How would I go about adding a checkbox. From your instructions I can definately do the rest, but the checkbox stumps me.

Oh and thank you very much for the instructions, I love that my customers can be logged in all of the time.

Pat
20 Feb 2007, 00:15
#13
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

hey, no problem!

it's a template file you should first copy into your own template-directory.
  1. copy the file "includes/templates/template_default/templates/tpl_login_default.php" to "your_template_dir/templates/tpl_login_default.php"
    _
  2. in this file the login box is around line 50. just there add the checkbox with a code like that:
    "<input id="permLogin" name="permLogin" type="checkbox" checked> stay logged in"
20 Feb 2007, 16:12
#14
blindside avatar

blindside

Totally Zenned

Join Date:
Sep 2004
Posts:
1,237
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Good stuff, crazy_chris. :thumbsup:
20 Feb 2007, 22:35
#15
pdprenty avatar

pdprenty

New Zenner

Join Date:
Sep 2006
Posts:
58
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

Hi crazy_chris, I just wanted to stop by and thank you for this.

I haven't got it working yet, (I got the tick box and the cookie imbeds it'self, but it does not log me back in again) but I will play around with it and I am sure I will be able to figure it out. It is likely I just put the code in the wrong spot, so I will look at the logic of the statements.

Again, thanks

Pat
23 Feb 2007, 00:28
#16
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

Hmm - I get this error
1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
in:
[SELECT customers_password FROM zen_customers WHERE customers_id=]


And the code I have copied and pasted from above and placed exactly where recommended in includes/modules/pages/login/header_php.php is
if (substr_count($_COOKIE["zencart_cookie_permlogin"], "~~~") > 1) {
		if (empty($_SESSION['customer_id'])) {
			$c = explode("~~~", $_COOKIE["zencart_cookie_permlogin"]);

			$q = "SELECT customers_password FROM " . TABLE_CUSTOMERS . " WHERE customers_id=" . $c[0];
			$r = $db->Execute($q);

			$pw_cookie = zen_db_prepare_input($c[7]);
			$pw_zencart = $r->fields['customers_password'];

			if ($pw_cookie == $pw_zencart) {
				$_SESSION['customer_id'] = $c[0];
				$_SESSION['customer_default_address_id'] = $c[1];
				$_SESSION['customers_authorization'] = $c[2];
				$_SESSION['customer_first_name'] = $c[3];
				$_SESSION['customer_last_name'] = $c[4];
				$_SESSION['customer_country_id'] = $c[5];	
				$_SESSION['customer_zone_id'] = $c[6];
				$_SESSION['cart']->restore_contents();
			}
		}
	}


I'm no expert, but there doesn't seem to be anything wrong with that. And I've checked in the db that the required data is present. :unsure:
23 Feb 2007, 10:21
#17
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

hey, is this a joke... because you just put the lines in the wrong file!! :blush:

the code you just posted (for automatically logging in) is meant to be put in "/includes/modules/pages/index/header_php.php"

the file "includes/modules/pages/login/header_php.php" (where you put the mentioned code) is for the original login-process where you set the cookie for the permanent login.

:P if you experience any troubles, post again!
23 Feb 2007, 10:32
#18
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

Damn - my human side is showing again! :D

But actually, not as bas as it seemed...I HAD put it in the right place - I had just pasted the wrong filename in that previous post.
23 Feb 2007, 10:43
#19
crazy_chris avatar

crazy_chris

New Zenner

Join Date:
Feb 2007
Posts:
38
Plugin Contributions:
0

Re: Is a Permanent Login (Auto-Login) Possible?

hehe, alright then :P

well, it seems, it doesn't find the customer_id in the cookie.

could you please add this code before the "$c = explode(....)":
"echo $_COOKIE["zencart_cookie_permlogin"];"
and post the output here?
23 Feb 2007, 10:54
#20
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Posts:
3,644
Plugin Contributions:
6

Re: Is a Permanent Login (Auto-Login) Possible?

Will do . but while I'm doing that, could you be a bit more specific about
does all the stuff around line 70. just after this we hook in. put that code there


Should it be at about line 72 after $check_country or about line 80 after the $_SESSION lines?

This one is in login/header_php.php