Jump to content

Why can't I log in?


budder

Recommended Posts

If you were php4 why wouldn't you log me in with this script? Php5 have no problemo :b

<?PHP 
$user = addslashes($_POST['username']); 
$pass = md5($_POST['password']); 

if(!isset($_POST['username']) || !isset($_POST['password']) OR !isset($_POST['login'])) {
header("location: login.html");
}
else {

$dbHost		=	"xx";
$dbUser		=	"xx";
$dbPass		=	"xx";
$dbDatabase	=	"x";



$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database."); 

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database."); 

$result=mysql_query("select * from users where username='" . $user . "' AND password='" . $pass . "'", $db); 



$rowCheck = mysql_num_rows($result); 
if($rowCheck > 0){ 
while($row = mysql_fetch_array($result)){ 


  session_start(); 
  $_SESSION['username'] = $user;


  echo 'Success!'; 


  header( "Location: inde_x.php" ); 

  } 

  } 
  else { 



  echo 'Forkert brugernavn eller kodeord.'; 

  
  } }
  ?> 

 

Link to comment
Share on other sites

When I remove the addslashes(); and md5(); it will login but with a headers already sent error.

I got one user in my database that haven't been md5(); with the password and ony that user will log in (with error) when I remove the addslashes and md5();

Link to comment
Share on other sites

But i got this at the top of my script:

$user = addslashes($_POST['username']);

$pass = md5($_POST['password']);

 

Should md5(); be in the $result ?

 

Im going to try it out (:

 

Hmm, still getting wrong pass og username.

 

Maybe I should make af if statement:

 

if username wrong {

username wrong

elseif password wrong {

password wrong

else {

Both wrong

Link to comment
Share on other sites

try it for username only.

do one more thing check whether u are getting the post values correctly

 

$result=mysql_query("select * from users where username='" . $user . "' AND password='" . $pass . "'", $db); 

 

remove the mysql_query and do some thing like this

 

 

$result=("select * from users where username='" . $user . "' AND password='" . $pass . "'", $db); 
echo $result;

 

now run the same query in ur mysql and see what results u are getting..

Link to comment
Share on other sites

With og without the mysql_real_escape_string there is no slashes. Only getting at error when trying to display the output from the mysql_query

 

$data = "select*from users where username='" . $user . "' AND password='" . $pass . "'";

 

echo $data;

 

Getting the syntax error, unexpected T_VARIABLE

when adding that line.

Link to comment
Share on other sites

Alright this is kind a wired but here we go:

<?PHP 
$user = mysql_real_escape_string($_POST['username']); 
$pass = ($_POST['password']);  

if(!isset($_POST['username']) || !isset($_POST['password']) OR !isset($_POST['login'])) {
header("location: login.html");
}
else {

$dbHost		=	"x";
$dbUser		=	"x";
$dbPass		=	"x";
$dbDatabase	=	"x";



$db = mysql_connect("$dbHost", "$dbUser", "$dbPass") or die ("Error connecting to database."); 

mysql_select_db("$dbDatabase", $db) or die ("Couldn't select the database."); 

$result=mysql_query("select * from users where username='" . $user . "' AND password='" . md5($pass) . "'", $db);


$rowCheck = mysql_num_rows($result); 
if($rowCheck > 0){ 
while($row = mysql_fetch_array($result)){ 


  session_start(); 
  $_SESSION['username'] = $user;


  echo 'Success!'; 


  header( "Location: inde_x.php" ); 

  } 

  } 
  else { 



  echo 'Forkert brugernavn eller kodeord.'; 

  
  } }
  ?> 

 

Now it's working with the line but still got my problem. But added this line:

$data = "select*from users where username='" . $user . "' AND password='" . $pass . "'";

 

echo $data;

 

And got this:

username='test25' AND password='137dcec44002170db2d2dcd9c70dbebf'

 

And checks if the md5(pass) are the same as in the DB:

17 test25 137dcec44002170db2d2

 

Hmm what the?

I have just added this user with following mysql line:

INSER INTO users (username,password) VALUES(

'test25',md5('magnus'));

 

Why don't they match?

 

Could it be that the row isn't long enough?  ::)

 

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.