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
I need help with login errors
Old 05-23-2009, 11:21 AM I need help with login errors
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
Ok this is the login script I am running,

PHP Code:
<?php include("head.php"); ?>

<?php
if (!$email || !$pass) {
    print 
"Please fill out all fields.";
    include(
"foot.php");
    exit;
}
$logres mysql_num_rows(mysql_query("select * from players where email='$email' and pass='$pass'"));
if (
$logres <= 0) {
    print 
"Login failed. If you have not already, please signup. Otherwise, check your spelling and login again.";
    include(
"foot.php");
    exit;
} else {
    
session_register("email");
    
session_register("pass");
    print 
"Welcome. <meta http-equiv=refresh content=0;URL=updates.php> If you are not redirected to our city please click <a href=updates.php>here</a> to continue..";
}
?>

<?php include("foot.php"); ?>
And when i try to log in i get the "Please fill out all fields"

Can someone please help me?

Thanks alot, Ash~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
 
Register now for full access!
Old 05-23-2009, 01:26 PM Re: I need help with login errors
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Can you post the login form?

I noticed you never retrieve $email or $pass from $_POST, this will fail if register globals is off. Also, from your query I noticed that you are storing raw passwords in your database. You should hash your passwords before sending them to the database.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-23-2009, 01:33 PM Re: I need help with login errors
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
Here is the form
HTML Code:
<form method=post action=login.php>
  <div align="center">
    <table>
      <tr> 
        <td><div align="center">Email:</div></td>
        <td><div align="center"> 
            <input type=text name=email>
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">Pass:</div></td>
        <td><div align="center"> 
            <input type=password name=pass>
          </div></td>
      </tr>
      <tr> 
        <td colspan=2 align=center><div align="center"> 
            <input type=submit value=Login>
          </div></td>
      </tr>
    </table>
  </div>
  <div align="center"></div>
</form>
And how would i hash them?

Thanks alot, Ash~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Old 05-23-2009, 01:46 PM Re: I need help with login errors
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try this:

PHP Code:
<?php include("head.php"); ?> 

<?php
$email 
= isset($_POST['email']) ? $_POST['email'] : false;
$pass = isset($_POST['pass']) ? $_POST['pass'] : false;

if (!
$email || !$pass) { 
    print 
"Please fill out all fields."
    include(
"foot.php"); 
    exit; 

$logres mysql_num_rows(mysql_query("select * from players where email='$email' and pass='$pass'")); 
if (
$logres <= 0) { 
    print 
"Login failed. If you have not already, please signup. Otherwise, check your spelling and login again."
    include(
"foot.php"); 
    exit; 
} else { 
    
session_register("email"); 
    
session_register("pass"); 
    print 
"Welcome. <meta http-equiv=refresh content=0;URL=updates.php> If you are not redirected to our city please click <a href=updates.php>here</a> to continue.."

?> 

<?php include("foot.php"); ?>
Code:
<form method="post" action="login.php">
  <div align="center">
    <table>
      <tr> 
        <td><div align="center">Email:</div></td>
        <td><div align="center"> 
            <input type="text" name="email" />
          </div></td>
      </tr>
      <tr> 
        <td><div align="center">Pass:</div></td>
        <td><div align="center"> 
            <input type="password" name="pass" />
          </div></td>
      </tr>
      <tr> 
        <td colspan=2 align=center><div align="center"> 
            <input type="submit" value="Login" />
          </div></td>
      </tr>
    </table>
  </div>
  <div align="center"></div>
</form>
I added the code to retrieve the email and pass from post. I also added quotes to your input field attributes in your form.

Regarding the password hashing. You shouldn't store or transmit raw password, instead you can use a hash function like sha1 to encode them. You store the encoded password in your database. When a user enters their password you encode it and compare it to the already encoded password in the database.

PHP Code:
$pass sha1($_POST['pass']); 
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is offline
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 05-23-2009, 01:54 PM Re: I need help with login errors
Skilled Talker

Posts: 78
Name: Ash Kwil
Trades: 0
Ok this actually goes onto the redirect part but it then displays "Invalid Login" on a blank white page.

How would i incorperate the hash thing then as im a little confused however i do grasp the concept.

Thanks alot for help, Ash~
Ashkwil is offline
Reply With Quote
View Public Profile Visit Ashkwil's homepage!
 
Reply     « Reply to I need help with login errors
 

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.65876 seconds with 12 queries