VickP07
11-08-2011, 02:49 AM
Okay guys so im trying to make a simple php login page that requires a user to enter in his/her username and password.
The password in my users table has a datatype of BLOB and when the user adds users into the DB i am doing a AES_ENCRYPT to save the password in the DB but encrypted.
Right now i am having trouble and can't figure out what i am missing or doing wrong? I have already tried to DEBUG and echo out my sql statement but i still can't figure out what the problem is and why the login form wont work when the user enters in the right username and password!
config.php:
<?
$conn = mysql_connect( "localhost", "root", "temp1234" );
$conn or die( "Error connecting: " . mysql_error() );
$db_name = "DoctorsOfficeDB";
mysql_select_db( $db_name )
or die( "Bad db name: $db_name" );
?>
Login.php:
<?php
include("config.php");
//start session
session_start();
if( $_POST )
{
// username and password sent from Form
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$sql="SELECT user_id FROM users WHERE username='$myusername' and aes_decrypt(pword='$mypassword');";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;
header("Location: welcome.php");
exit();
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<html>
<body>
<form action="Login.php" method="post">
<fieldset>
<legend>Login Information:</legend>
UserName: <input type="text" size="20" name="username" /><br />
Password: <input type="password" size="20" name="password" /><br />
</fieldset>
<input type="submit" value="Submit">
</form>
</body>
</html>
lock.php
<?php
include("config.php");
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysql_query("select username from users where username='$user_check' ");
$row=mysql_fetch_array($ses_sql);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location: Login.php");
}
?>
logout.php :
<?php
session_start();
if(session_destroy())
{
header("Location: Login.php");
}
?>
welcome.php:
<?php
include('lock.php');
?>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2><a href="logout.php">Sign Out</a></h2>
</body>
</html>
The password in my users table has a datatype of BLOB and when the user adds users into the DB i am doing a AES_ENCRYPT to save the password in the DB but encrypted.
Right now i am having trouble and can't figure out what i am missing or doing wrong? I have already tried to DEBUG and echo out my sql statement but i still can't figure out what the problem is and why the login form wont work when the user enters in the right username and password!
config.php:
<?
$conn = mysql_connect( "localhost", "root", "temp1234" );
$conn or die( "Error connecting: " . mysql_error() );
$db_name = "DoctorsOfficeDB";
mysql_select_db( $db_name )
or die( "Bad db name: $db_name" );
?>
Login.php:
<?php
include("config.php");
//start session
session_start();
if( $_POST )
{
// username and password sent from Form
$myusername = $_POST['username'];
$mypassword = $_POST['password'];
$sql="SELECT user_id FROM users WHERE username='$myusername' and aes_decrypt(pword='$mypassword');";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
session_register("myusername");
$_SESSION['login_user']=$myusername;
header("Location: welcome.php");
exit();
}
else
{
$error="Your Login Name or Password is invalid";
}
}
?>
<html>
<body>
<form action="Login.php" method="post">
<fieldset>
<legend>Login Information:</legend>
UserName: <input type="text" size="20" name="username" /><br />
Password: <input type="password" size="20" name="password" /><br />
</fieldset>
<input type="submit" value="Submit">
</form>
</body>
</html>
lock.php
<?php
include("config.php");
session_start();
$user_check=$_SESSION['login_user'];
$ses_sql=mysql_query("select username from users where username='$user_check' ");
$row=mysql_fetch_array($ses_sql);
$login_session=$row['username'];
if(!isset($login_session))
{
header("Location: Login.php");
}
?>
logout.php :
<?php
session_start();
if(session_destroy())
{
header("Location: Login.php");
}
?>
welcome.php:
<?php
include('lock.php');
?>
<html>
<head>
<title>Welcome</title>
</head>
<body>
<h1>Welcome <?php echo $login_session; ?></h1>
<h2><a href="logout.php">Sign Out</a></h2>
</body>
</html>