Jump to content

[SOLVED] Simple login problem. HELP!


phpwiz

Recommended Posts

ok i have made this login script and it connects to the database and all but it says "Incorrect password!" when i KNOW i put in the correct password, here is the code.

 

login2.php

<?php

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

if ($username)
{

include "connect.php";

$query = mysql_query("SELECT * FROM users WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows!=0)
{

while ($row = mysql_fetch_assoc($query))
{
		$dbusername = $row['username'];	
		$dbpassword = $row['password'];	
}

// check to see if they match
if ($username==$dbusername&&$password==$dbpassword)
{
	echo "You have sucessfully been logged in! <a href='mem.php'>Click here!</a>";
	$_SESSION['username']=$username;	
}
else
	die("Incorrect password!");

}
else
die("That user Does NOT exist");



}
else
die("Please enter a username and a password!");



?>

 

 

Link to comment
Share on other sites

while ($row = mysql_fetch_assoc($query))

  {

        $dbusername = $row['username']; 

        $dbpassword = $row['password']; 

  }

 

modify to:

 

list($dbusername, $dbpassword) = mysql_fetch_array($query, MYSQL_NUM);

 

Still says "Incorrect password!"

 

and i have even changed my password in the DB to make sure it is the rite password.

Link to comment
Share on other sites

After the query check you're getting results.

 

If you are echo the results and compare them to what's being entered into the form.

 

Yes, i am

 

i tried taking out the md5 because in the DB it is not encrypted rite now.

 

still says incorrect password

Link to comment
Share on other sites

try this;

 

<?php
session_start();
if(isset($_POST['username']))
{
$username = $_POST['username'];
$password = md5($_POST['password']); //remove md5 if needed
include "connect.php";
$query = mysql_query("SELECT `password` FROM `users` WHERE `username`='$username' LIMIT 1");

$numrows = mysql_num_rows($query);
if ($numrows > 0)
{

	$row = mysql_fetch_assoc($query);
	$dbpassword = $row['password'];

	// check to see if they match
var_dump($password);
echo '<br />should equal<br />';
var_dump($dbpassword);
	if ($password==$dbpassword)
	{
		echo "You have sucessfully been logged in! <a href='mem.php'>Click here!</a>";
		$_SESSION['username']=$username;   
	}
	else
	{
		die("Incorrect password!");
	}

}
else
{
	die("That user Does NOT exist");
}
}
else
{
die("Please enter a username and a password!");
}
?>

Link to comment
Share on other sites

try this;

 

<?php
session_start();
if(isset($_POST['username']))
{
$username = $_POST['username'];
$password = md5($_POST['password']); //remove md5 if needed
include "connect.php";
$query = mysql_query("SELECT `password` FROM `users` WHERE `username`='$username' LIMIT 1");

$numrows = mysql_num_rows($query);
if ($numrows > 0)
{

	$row = mysql_fetch_assoc($query);
	$dbpassword = $row['password'];

	// check to see if they match
var_dump($password);
echo '<br />should equal<br />';
var_dump($dbpassword);
	if ($password==$dbpassword)
	{
		echo "You have sucessfully been logged in! <a href='mem.php'>Click here!</a>";
		$_SESSION['username']=$username;   
	}
	else
	{
		die("Incorrect password!");
	}

}
else
{
	die("That user Does NOT exist");
}
}
else
{
die("Please enter a username and a password!");
}
?>

 

this is what it echo'd out

string(32) "5f4dcc3b5aa765d61d8327deb882cf99" 
should equal
string( "password" Incorrect password!

 

 

 

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.