Hi,
I'm building a restricted access site with a Login/Password authentification.
I'm new to PHP and I would like to know if my application is SECURE and Ok to publish to Internet.
Can anyone check my code and tell me if they see security LACK in it ?
In the system, each page has an Include file which verify is the variable $_SESSION['session_allowed']= 1. If not, it redirect to an access denied page.
Thank you very much.
<?php
session_start();
/* For security reasons, if the variable $continue still == 1 at the end, the process
doesn't to check the password */
$continue = 1;
include ("connexion.php");
/* -------------------------------------------------------------------------------------- */
/* User loginname validation */
/* -------------------------------------------------------------------------------------- */
$result = mssql_query("SELECT * FROM tbl_users where login ='$user_login'")
or die ("Requête invalide");
/*Check if the the username exist in the database ?*/
If (mssql_num_rows($result) == 0)
{
$_SESSION['message_login'] = "The account $user_login doesn't exist.";
$continue = 1;
header("location: login.php");
}
/*If the username exist, is the tryout security overpassed ?*/
Elseif (mssql_num_rows($result) == 1)
{
$resultlogin=mssql_fetch_Array($result);
extract($resultlogin);
If ($login_tryout >= 3)
{
$_SESSION['message_login'] = "The account $login have been disabled because of to many login attempts. Please contact Luc Grandchamp.";
$continue = 1;
header("location: login.php");
}
Else
{
$continue=0;
}
}
// --------------------------------------------------------------------------------------
// Password validation
// --------------------------------------------------------------------------------------
if ($continue == 0)
{
$resultpass = mssql_query("SELECT * FROM tbl_users where login ='$user_login' and password ='$login_password'")
or die ("Requête invalide");
//Is the password right ?
// No
If (mssql_num_rows($resultpass) == 0)
{
$_SESSION['message_login'] ="The password for the user $user_login is not right.";
$updated_login_tryout = ++$login_tryout ;
$result_tryout = mssql_query("
UPDATE tbl_users
SET
tbl_users.login_tryout = '$updated_login_tryout'
WHERE tbl_users.login ='$user_login';")
or die ("Requête invalide");
$continue = 1;
header("location: login.php");
}
// Yes
Elseif (mssql_num_rows($resultpass) == 1)
// Define my session's variables
{
$ligne_resultpass = mssql_fetch_array($resultpass);
extract ($ligne_resultpass);
$_SESSION['session_allowed']= 1;
$_SESSION['session_group']= "$user_group";
$_SESSION['session_login_name']= "$login";
$_SESSION['session_id_users']= "$id_users";
$_SESSION['session_user_firstname']= "$user_firstname";
$_SESSION['session_user_lastname']= "$user_lastname";
$_SESSION['message_login']= "";
$_SESSION['user_p_touch']= "$user_p_touch";
// Redirect to the user group directory
if ($user_group ==1)
{
header("location: administrator/menu.php");
}
elseif ($group ==2)
{
header("location: /2");
}
elseif ($group ==3)
{
header("location: /3");
}
elseif ($group ==4)
{
header("location: /4");
}
}
}
?>
I'm building a restricted access site with a Login/Password authentification.
I'm new to PHP and I would like to know if my application is SECURE and Ok to publish to Internet.
Can anyone check my code and tell me if they see security LACK in it ?
In the system, each page has an Include file which verify is the variable $_SESSION['session_allowed']= 1. If not, it redirect to an access denied page.
Thank you very much.
<?php
session_start();
/* For security reasons, if the variable $continue still == 1 at the end, the process
doesn't to check the password */
$continue = 1;
include ("connexion.php");
/* -------------------------------------------------------------------------------------- */
/* User loginname validation */
/* -------------------------------------------------------------------------------------- */
$result = mssql_query("SELECT * FROM tbl_users where login ='$user_login'")
or die ("Requête invalide");
/*Check if the the username exist in the database ?*/
If (mssql_num_rows($result) == 0)
{
$_SESSION['message_login'] = "The account $user_login doesn't exist.";
$continue = 1;
header("location: login.php");
}
/*If the username exist, is the tryout security overpassed ?*/
Elseif (mssql_num_rows($result) == 1)
{
$resultlogin=mssql_fetch_Array($result);
extract($resultlogin);
If ($login_tryout >= 3)
{
$_SESSION['message_login'] = "The account $login have been disabled because of to many login attempts. Please contact Luc Grandchamp.";
$continue = 1;
header("location: login.php");
}
Else
{
$continue=0;
}
}
// --------------------------------------------------------------------------------------
// Password validation
// --------------------------------------------------------------------------------------
if ($continue == 0)
{
$resultpass = mssql_query("SELECT * FROM tbl_users where login ='$user_login' and password ='$login_password'")
or die ("Requête invalide");
//Is the password right ?
// No
If (mssql_num_rows($resultpass) == 0)
{
$_SESSION['message_login'] ="The password for the user $user_login is not right.";
$updated_login_tryout = ++$login_tryout ;
$result_tryout = mssql_query("
UPDATE tbl_users
SET
tbl_users.login_tryout = '$updated_login_tryout'
WHERE tbl_users.login ='$user_login';")
or die ("Requête invalide");
$continue = 1;
header("location: login.php");
}
// Yes
Elseif (mssql_num_rows($resultpass) == 1)
// Define my session's variables
{
$ligne_resultpass = mssql_fetch_array($resultpass);
extract ($ligne_resultpass);
$_SESSION['session_allowed']= 1;
$_SESSION['session_group']= "$user_group";
$_SESSION['session_login_name']= "$login";
$_SESSION['session_id_users']= "$id_users";
$_SESSION['session_user_firstname']= "$user_firstname";
$_SESSION['session_user_lastname']= "$user_lastname";
$_SESSION['message_login']= "";
$_SESSION['user_p_touch']= "$user_p_touch";
// Redirect to the user group directory
if ($user_group ==1)
{
header("location: administrator/menu.php");
}
elseif ($group ==2)
{
header("location: /2");
}
elseif ($group ==3)
{
header("location: /3");
}
elseif ($group ==4)
{
header("location: /4");
}
}
}
?>