Jump to content

cookies


brown2005

Recommended Posts

	if(isset($_COOKIE['ID_my_site']))
{ 

	echo"yes there is a cookie";

}else{
  
	$hour = time() + 3600; 

	$username = "rberbe2002";
	$password = "charliew";

	setcookie(ID_my_site, $username, $hour); 

	setcookie(Key_my_site, $password, $hour);

}

 

I am trying to create a loging script. I want this to be as secure as possible. I am trying to see if implementing cookies will work, but obviously the cookie set if someone could get this off my comp they could see my username and password. how can i make this more secure? and is there anyway to encrypt a cookie so it cant be read

Link to comment
Share on other sites

The cookies you use to identify a visitor should not use any direct identifying information, such as a username or password. You should also not store a fixed/static value, such as the md5 of a password as that would prevent you from regularly regenerating a new value to guard against the cookie being hijacked and allowing someone to impersonate the actual user.

 

What you should do is generate a unique id (see this function - uniqid) that is then stored in the cookie and stored in your user table for that visitor. The unique id is then used to associate the visitor with his record in the user table. You can then regenerate this unique id, updating the cookie value and the value in the user table, as needed (some people regenerate it on every page visit) to help guard against someone impersonating the actual visitor if they get a hold of the value in the cookie.

Link to comment
Share on other sites

Yes, but that is true of any method you use that relies on a value in a cookie to identify a visitor.

 

The unique identifier method at least would only allow access on your site (people often use the same username and password everywhere.) By regenerating the unique id while the original visitor is active on your site, you limit the time frame where any stolen unique id can be used by someone else.

 

For any operation that requires more security, such as changing the password or the email address associated with a visitor, you would not just rely on someone having a cookie that identifies them, you would require that they re-enter the username and password to re-authenticate who they are.

 

You also need to store the logged in/logged out status in the user table so that when someone manually logs out or is automatically logged out a time after their last activity on your site, the only way they can log in is by providing the correct username and password. Just having a cookie with the correct value in it should not be enough to indicate that someone is logged in. The cookie should only serve to identify who they are.

Link to comment
Share on other sites

Using a cookie (long term - remember me) or a session (short term - one browser session) to identify the visitor both have the same security issues and solutions mentioned in this thread. And in fact, the unique id suggested for the cookie value is essentially what a session id does.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.