Jump to content

Login Process Problems


Mat_dennison

Recommended Posts

Hi

 

Im doing a login for a website I've built and Im having troubles,

 

The connection to the actual database works fine, no errors,  but when trying to verify data in the database to log on and get to a secure area i just get the incorrect username or password that i created for when details are incorrect.

 

heres the code where the problem lies

 

Any help would be appreciated

 

<?php
session_start();
require("db_connect.php");

$username = $_POST['uname'];  
$password = $_POST['pword'];

$sql = "SELECT * 
		FROM login_details 
		WHERE username='$username' 
		AND password='$password'";
$results = mysql_query($sql, $connect);
$numofrows = mysql_num_rows($results);
if ($numofrows == 1) {
	$_SESSION['username'] = $row['username'];
	$_SESSION['loggedin'] = true;
	header ("Location: secure_page.php");
	die();
} else { 
	$_SESSION['error']= "Icorrect Username Or Password"; 
	header("Location: login.php");
	die();
	}

?>

 

Link to comment
Share on other sites

OK. Let's echo the query regardless of whether there's an error or not then. Add  the indicated line, and post it's output.

 

$sql = "SELECT * 
FROM login_details 
WHERE username='$username' 
AND password='$password'";
echo "<br>Query string: $sql<br>"; // <---- Add that line
$results = mysql_query($sql, $connect);

Link to comment
Share on other sites

Then that indicates a problem with the integrity of the data. A username/password SELECT query should only ever match exactly zero or exactly one record. If it matches zero, the record doesn't exist, which isn't a problem. If it matches one record, the password and username pair exist, and were entered correctly. If more than one match is found, the results should be considered ambiguous, and the login process should be halted immediately. After all, if more than one user has the same username/password combination, that is a serious design flaw.

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.