Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Remember username / password
Old 03-09-2008, 09:48 AM Remember username / password
choskins102's Avatar
Super Talker

Posts: 137
Name: Casey
Trades: 3
Hey, guys.

Can someone tell me, or point me in the right direction, how to save a person's username and password. Basically, when someone logs in, I want them to have the option to remain logged in even if they leave the site. Currently, my site uses sessions, not cookies.
choskins102 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-09-2008, 05:25 PM Re: Remember username / password
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Sessions are essentially cookies which point to a file of information on a server.

I would recommend you set a cookie containing the username/pass (Encrypted of course) user side which when present logs them in (Quite similar to what lots of forums do I think).

The code would be something like:
PHP Code:
<?php
$value 
base64_encode("$Username"."$Password"); // Quite insecure. You would need to unravel with a base64_decode and a split. 
$expiretime time()+3600// this would mean, in a days time.
setcookie("logininfo"$value$expiretime"/example_folder/"".example.com"1true);
?>
Thats quite a bad example, but a good prod in the right direction

If you want better security md5 the username and pass with salt along with a session info. Then possibly a bit of extra info in the cookie (like access IP and so on). It's also a bad idea to have a cookie name as "logininfo", but that was me just being quick.
For more information on cookies see:
http://uk2.php.net/manual/en/function.setcookie.php
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 03-09-2008 at 05:33 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 03-09-2008, 05:34 PM Re: Remember username / password
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Bad idea...
Never ever store the password in a cookie. Even if it's encrypted.
The encryption is to make harder the work of a hacker who did get in, not the 1st line of defense...

What I usually do is that I save a hash in the database for each users, and set the cookie with that same hash with a validity of a week, or so.

Then, each page view update the hash value both in db and in the cookie, and it update the cookie validity.
This way, the content is changing for each requests the user do.

Now, when a user which is not identified comes, look for the value of that hash in the cookie, and log in automatically if the content match 1 record.

That way, no username nor password are in the cookie, end the entropy on the checked field makes it a lot harder to overcome.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 03-09-2008 at 05:35 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 03-09-2008, 05:39 PM Re: Remember username / password
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
Quote:
Originally Posted by tripy View Post
What I usually do is that I save a hash in the database for each users, and set the cookie with that same hash with a validity of a week, or so.
Heh, I was going to cover that hehe ^^ Though that still raises the problem of if the computer/cookies gets stolen. A hacker could just do a JS injection and create to cookie themselves and there in.

Either way, it's all round never a great idea to store info user side. They sometimes block/delete them. For certain levels of security it's normally a good idea just to use sessions.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 03-10-2008, 04:07 AM Re: Remember username / password
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
I think in most cases it should be okay to store a user id in a cookie, unless security is a huge thing.

I personally use something which on every page load checks the session and cookie status, if cookie isset but session isnt it resets the session.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Remember username / password
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27413 seconds with 12 queries