Current location: Hot Scripts Forums » Programming Languages » PHP » Set Cookie Login Script !!! HELP !!!


Set Cookie Login Script !!! HELP !!!

Reply
  #1 (permalink)  
Old 11-05-03, 11:49 AM
Seldimi Seldimi is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Kozani, Greece
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Set Cookie Login Script !!! HELP !!!

Any good soul want to clean this code ??? I Get a lot of errors

(Username1 and Password1 are posted by a separate form and function_connect.php includes database connection. I saw it on a tutorial but couldn't make it work ....

PHP Code:

<?php


$username1 
$_POST['user'];
$password1 $_POST['pass'];
include 
"function_connect.php";

// valid login credentials 
if ($username1 && $password1) { 
$sql="SELECT id, username, password FROM pointgather WHERE 
username='
$username1' AND password='$password1'";
$result mysql_query ($sql) or die('Error: ' mysql_error());
$user_data mysql_fetch_array ($result);
$id $user_data ['id'];
$username $user_data ['username'];
$password $user_data ['password'];

 if (
$user_data['id'] > 0) { 
  
setcookie ("user"md5($user_data['username']));  
  
setcookie ("pass"md5($user_data['password']));  
  print 
"success"
 } else { 
$login_errortrue; } 


// grab current time 
$time=time(); 

// handle the logout event 
if ($logout == true) {     
 
setcookie ("user"md5($username1), $time-3200);  
 
setcookie ("pass"md5($password1), $time-3200);  
// header("Location: index.php"); 


// handle validation event 
if ($_POST[user] && $_POST[pass]) {     
 if (
$username1==$username && $password1==$password) { 
  
setcookie ("user"md5($username1), $time+3200);  
  
setcookie ("pass"md5($password1), $time+3200);  
 
// header("Location: index.php"); 
 
} else { $login_errortrue; } 


// handle login event, both successful and erroneous, or show login screen 
if ($login_error == true) { ?> 
 <table align=center style="font-family:arial; 
font-size:12; border:1 solid #000000;"> 
  <tr><td align=center bgcolor=#123dd4>LOGIN ERROR</td></tr> 
  <tr><td align=center><b>Invalid Username and/or Password</b><br><br>
<a href=index.php>Back</a></td></tr> 
</table> 
<? 
} elseif ($_COOKIE[user] == md5($username) && $_COOKIE[pass] == 
md5($password)) { ?> 
 <table align=center style="font-family:arial;
 font-size:12; border:1 solid #000000;"> 
  <tr><td align=center bgcolor=#123dd4>SECURE AREA</td></tr> 
  <tr><td align=right>
<a href=index.php?logout=true>Logout</a></td></tr> 
  <tr><td>You have successfully logged in.<br><br> 
   Encrypted Username: <b><?=  $_COOKIE['user'?></b><br> 
   Encrypted Password: <b><?= $_COOKIE['pass'?></b><br> 
  </td></tr> 
</table> 
<? 
}
?>
Reply With Quote
  #2 (permalink)  
Old 11-05-03, 02:21 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
first thing I noticed is that you are not checking if the user name existed or not !? you just assigned ID,user and password to cookie !
and then you are using MD5() to encyrpt the username ?? why ? also it is recommended to encrypt the password in database not in cookie !! not to mention it's a security risk to store the password in a cookie ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 11-06-03, 03:50 AM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
storing the md5'ed password in the cookie is not an extreme security risk though if you can avoid it, you should avoid it

encrypting the username is slightly useless, thats for sure.

you said you were getting errors. what kind of errors do you get?
Reply With Quote
  #4 (permalink)  
Old 11-06-03, 08:46 AM
Seldimi Seldimi is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Kozani, Greece
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Multiple errors
I am sure this code is not correct, can sb fix it ?
Reply With Quote
  #5 (permalink)  
Old 11-06-03, 03:35 PM
Stefan's Avatar
Stefan Stefan is offline
Junior Code Guru
 
Join Date: Jun 2003
Location: Utrecht, The Netherlands
Posts: 599
Thanks: 0
Thanked 0 Times in 0 Posts
can you please post the errors here, so it is easier for us to check what might be wrong? we can not test this code on our local system since we don't have your full system that this is a part of.
Reply With Quote
  #6 (permalink)  
Old 11-08-03, 05:45 AM
Seldimi Seldimi is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Kozani, Greece
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
Zip File

Here is the zip file with the 2 files I try to run ...
Attached Files
File Type: zip Script.zip (1.3 KB, 168 views)
Reply With Quote
  #7 (permalink)  
Old 11-08-03, 07:05 AM
The Hooded's Avatar
The Hooded The Hooded is offline
Newbie Coder
 
Join Date: Nov 2003
Location: Toronto, Canada
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
I took a look at your script an it looks like it would work depending on the version and configuration of your php.
I sugguest that you check your
phpinfo()
to see how yours is setup and version you are using.
And if your uploading this to a different server know it's PHP information and setup.
__________________
The Hooded
Website Developing is my hobby
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Looking for a good review management script griz_fan Script Requests 10 07-29-07 05:08 AM
login script required lochie Script Requests 2 03-06-04 07:44 PM
login script @NVP@ Script Requests 2 09-30-03 12:44 AM
help me improve my login script please paulj000 PHP 8 08-15-03 05:37 PM
Need help with a script boardpix PHP 7 06-08-03 11:37 PM


All times are GMT -5. The time now is 07:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.