...

View Full Version : Login doesn't work



Pandabeer
05-05-2009, 11:28 AM
As the title says, my login doesn't work i can login with each password their not hashed maybe in the future i will



//login.php
<form method=post action=logprocess.php>
Username:<input type=text name=usernameftw><br>
Password:<input type=password name=passwordftw><br>
<input type=submit value='Login.'><input type=reset value='Reset.'>

// logprocess.php
<? session_start();
$_SESSION['logged'] = 0;
$name = $_POST['usernameftw'];
$pass = $_POST['passwordftw'];
if($name == "" and $pass == "")
{
Header ("Location: login.php?error=3");
}
if($name == "")
{
Header ("Location: login.php?error=1");
}
if($pass == "")
{
Header ("Location: login.php?error=2");
}
mysql_connect("localhost", "root", "password")
or die("Could not connect to database");
mysql_select_db("database") or die("Could not select database");
$sql = mysql_query("SELECT * FROM accounts WHERE name='$name'");
if(!$sql)
{
Header ("Location: login.php?error=4");
}
while($a = mysql_fetch_array($sql))
{
if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}
$_SESSION['logid'] = $a['user_id'];
}
$_SESSION['logged'] = 1;
Header ("Location: mindex.php");
?>

Hayyel
05-05-2009, 11:34 AM
I assume this is supposed to be mindex?


$_SESSION['logged'] = 1;
Header ("Location: mindex.php");

Pandabeer
05-05-2009, 11:42 AM
I assume this is supposed to be mindex?


$_SESSION['logged'] = 1;
Header ("Location: mindex.php");

mindex.php is just a page that shows Welcome to members area, if you not logged in it says please login

abduraooft
05-05-2009, 11:57 AM
As the title says, my login doesn't work i can login with each password their not hashed maybe in the future i will Are you getting any error? If not, add
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL);
?> at the top of your page. Also, it's a good idea to have an error free markup while debugging something. Validate your markup using http://validator.w3.org/#validate_by_input

Pandabeer
05-05-2009, 11:59 AM
Are you getting any error? If not, add
<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting (E_ALL);
?> at the top of your page.

i dind't get errors, but i will get errors if i do something wrong, i just have the problem that if my password = 'sheep' i can login with 'goat' and 'sheep' and every word i put in..

abduraooft
05-05-2009, 12:04 PM
while($a = mysql_fetch_array($sql))
{
if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}
$_SESSION['logid'] = $a['user_id'];
}
$_SESSION['logged'] = 1;
Header ("Location: mindex.php"); try the following instead

$a = mysql_fetch_array($sql);

if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}
else{
$_SESSION['logid'] = $a['user_id'];
$_SESSION['logged'] = 1;
Header ("Location: mindex.php");
}

Pandabeer
05-05-2009, 01:57 PM
try the following instead

$a = mysql_fetch_array($sql);

if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}
else{
$_SESSION['logid'] = $a['user_id'];
$_SESSION['logged'] = 1;
Header ("Location: mindex.php");
}

thanks for that, but now even if i fill in the right password, it says Password is incorrect! (login.php?error=5)


if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}


// whole shizzel
session_start();
$_SESSION['logged'] = 0;
$name = $_POST['usernameftw'];
$pass = $_POST['passwordftw'];
if($name == "" and $pass == "")
{
Header ("Location: login.php?error=3");
}
if($name == "")
{
Header ("Location: login.php?error=1");
}
if($pass == "")
{
Header ("Location: login.php?error=2");
}
mysql_connect("localhost", "root", "password")
or die("Could not connect to database");
mysql_select_db("database") or die("Could not select database");
$sql = mysql_query("SELECT * FROM accounts WHERE name='$name'");
if(!$sql)
{
Header ("Location: login.php?error=4");
}
$a = mysql_fetch_array($sql);

if($pass != $a['password'])
{
Header ("Location: login.php?error=5");
}
else{
$_SESSION['logid'] = $a['user_id'];
$_SESSION['logged'] = 1;
Header ("Location: mindex.php");
}

abduraooft
05-05-2009, 03:52 PM
Are you really getting the required values from your DB? Put some echo/print_r statements to debug your code at intermediate steps, say

$a = mysql_fetch_array($sql);
echo '<pre>';print_r($a);echo '</pre>';

Hayyel
05-06-2009, 03:17 AM
Can you post your form please.

Pandabeer
05-10-2009, 11:11 AM
<form method=post action=logprocess.php>
Username:<input type=text name=usernameftw><br>
Password:<input type=password name=passwordftw><br>
<input type=submit value='Login.'><input type=reset value='Reset.'>


but if i print these things, itll work the problem is he wont get anything from the database.



Are you really getting the required values from your DB? Put some echo/print_r statements to debug your code at intermediate steps, say

$a = mysql_fetch_array($sql);
echo '<pre>';print_r($a);echo '</pre>';

well i did this but it wouldnt show anything.

abduraooft
05-10-2009, 11:46 AM
Try
$sql = mysql_query("SELECT * FROM accounts WHERE name='$name'") or die(mysql_error());



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum