Search
Left Quote    If at first you don't succeed, redefine success.
- Anon.    
Right Quote
 
[login] | [Register]
Forum Index » PHP and mySQL » Viewing Topic and Replies
Post Reply


        Viewing Topic: Login problem
  This user is offline  voppeh
  Subject: "Login problem" Posted: @ 11:25 pm on Nov 29 2007   
Member #: 495
Rank: User - (3)
Since: 11/29/07
Posts: 3

Hi, first of all i would like thank for a great site, it got lots of usefull stuff!

I have been doing my own site with members, but i got stuck on login part and went looking on webb for a solution and found the tutorial on this site. But im getting the same problem as with my own code, the password and username doesnt match those in the database: "Login Failure: An error occured, please verify your username and password are correct." (when taken from this site). Login.php is pretty much copy pasted with some changes in mysql syntax because i used my old database.

Code:
<?php
ob_start();

require_once('d b-connect.php') ;

if(isset($_SESS ION['username'] ) && isset($_SESSION ['password']))
{
//REDIRECT TO USERS PROFILE...
header("ht tp://localhost/ bokningssystemp hp/start.php&qu ot;);
} //end if logged in

//IF SUBMIT BUTTON PRESSED
if(isset($_POST ['submit']))
{
if(!$_POST['us ername']) die("Error : You must enter your username before logging in.");
if(!$_POST['pa ssword']) die("Error : You must enter your password before logging in.");

//set cookie if checked
if(!empty($_PO ST['stay_in']))
{
$joined =''.$_POST['use rname'].'[]'.md 5($_POST['passw ord']).'';
setcookie('logi n_cookie', $joined, 2147483647, '/', 'http://localho st/bokningssyst emphp/start.php ');
} //end if
//verify user...
$get_user = mysql_query(&qu ot;SELECT * FROM `klienter` WHERE anv = '".$_POST[ 'username'].&qu ot;' AND pass = '".md5 ($_POST['passwo rd'])."'&q uot;);
$q = mysql_fetch_obj ect($get_user);
if(!$q) die("Login Failure: An error occured, please verify your username and password are correct.") ;

//set session variables
$_SESSION['log ged_in'] = 1;
$_SESSION['use rname'] = $_POST['usernam e'];
$_SESSION['pas sword'] = $_POST['passwor d'];
session_write_ close();
header("h ttp://localhost /bokningssystem php/start.php&q uot;);

}
else
{
//show login form
?>
<form name="logi n" method="po st" action="&l t;? $_SERVER['PHP_S ELF']; ?>">
<table> <tr>
<td>Usern ame:<input type="text " id="userna me" name="user name">& lt;/td>
</tr>
<tr>
<td>Passw ord:<input type="pass word" id="passwo rd" name="pass word">& lt;/td>
</tr>
<tr>
<td>Submi t: <input type="subm it" value="Sub mit" name="subm it" id="submit "></ td>
</tr>
<tr>
<td>Remem ber? <input type="chec kbox" name="stay _in[]"> </td>
</tr>
</table>< br /> </form> <?
}//end else
?>


require_once('d b-connect.php') ; is working, but its containing if its of any use:

Code:
<?php
$koppling=@mysq l_connect(" ;localhost" ;,"root&qu ot;,"" ;)or die("kunde inte


    Viewed: 8,599 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Login problem" Posted: @ 12:08 am on Nov 30 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

Was your initial password stored with md5 encryption? that maybe the problem.




-bs0d | AllSyntax.com

    Viewed: 8,595 Times | Reply to This | To top
  This user is offline  voppeh
  Subject: "re: Login problem" Posted: @ 12:03 pm on Nov 30 2007    
Member #: 495
Rank: User - (3)
Since: 11/29/07
Posts: 3

Yes it was, i made that account using registering page of your tutorial.




    Viewed: 8,576 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Login problem" Posted: @ 3:09 pm on Nov 30 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

  voppeh said...

< i> Yes it was, i made that account using registering page of your tutorial.

Ah-hah! Found it im 99% sure. Your password table is setup to allow 20 characters, however the md5() function encrypts the string (password) into a 32 character hash. This explains your problems.

FYI: The 2nd page of the tutorial showed that your password field in the table should accept 32 characters. Good luck




-bs0d | AllSyntax.com

    Viewed: 8,571 Times | Reply to This | To top
  This user is offline  misterhaan
  Subject: "re: Login problem" Posted: @ 4:29 pm on Nov 30 2007    

Member #: 5
Rank: User - (213)
Since: 02/11/05
Posts: 148
From: chair

  bs0d said...

< i> setup to allow 20 characters, however the md5() function encrypts the string (password) into a 32 character hash.

i




please note that the above post is likely made up in its entirety.

    Viewed: 8,565 Times | Reply to This | To top
  This user is offline  bs0d
  Subject: "re: Login problem" Posted: @ 4:38 pm on Nov 30 2007    

Member #: 1
Rank: Admin. - (1,505)
Since: 02/06/05
Posts: 600
From: USA

The same here, those logical errors are the worst!




-bs0d | AllSyntax.com

    Viewed: 8,560 Times | Reply to This | To top
  This user is offline  voppeh
  Subject: "re: Login problem" Posted: @ 6:00 pm on Nov 30 2007    
Member #: 495
Rank: User - (3)
Since: 11/29/07
Posts: 3

Great, thx a lot for the help, gonna try fix that now.




    Viewed: 8,558 Times | Reply to This | To top
Viewing Page: 1 of 1


1 |

You must be logged in to post on the forums. Login or Register








"AllSyntax.com" Copyright © 2002-2018; All rights lefted, all lefts righted.
Privacy Policy  |  Internet Rank