Connecting Tech Pros Worldwide Help | Site Map

Noob security question

  #1  
Old December 21st, 2005, 11:15 AM
What nickname do you want?
Guest
 
Posts: n/a
I want to provide secured acces to a MySQL database. This is what I've
done. Firstly the relevant pages are in a folder to which Apache
requires password authentication. Then I have an HTML page with a form
to enter (MySQL) ID and password, which I POST to a PHP page which
tries to connect to the MySQL database, and if so starts a session...

$id = $_POST['ID'];
$pass=$_POST['password'];
if ($connect=mysql_pconnect("localhost",$id,$pass) )
{
session_start();
echo "Connected - using database 'test'<br>";
mysql_select_db("test");
$_SESSION["id"]=$id;
$_SESSION["password"]=$pass;
$_SESSION["start"]=time();
}
else
{
header("Location: http://127.0.0.1");
exit();
}

Subsequent PHP pages are like:

session_start();
$id=$_SESSION["id"];
$pass=$_SESSION["password"];
$start=$_SESSION["start"];
$duration = time()-$start;
if ($duration>10)
{
session_destroy();
header ("Location: http://127.0.0.1/timeout.htm");
exit();
}
$_session["start"]=time();

$connect=mysql_pconnect("localhost",$id,$pass);
$myQuery=...

Is this reasonably secure? What are the obvious holes? TIA

  #2  
Old December 21st, 2005, 03:55 PM
joe
Guest
 
Posts: n/a

re: Noob security question


You probably would want to hash the passwords in the database (e.g.
with sha1) as well as use SSL to encrypt communications between the
browser and the server. PHP session security can be discussed at length
but some issues you should consider are session hijacking, session
fixation, cross-site scripting, cross-site forgery requests, etc.

  #3  
Old December 21st, 2005, 03:55 PM
joe
Guest
 
Posts: n/a

re: Noob security question


Reread your question, and with regard to the mysql part of it, you can
place the db connection information in a separate file. Make sure you
validate/sanitize any input given by the user - use
mysql_real_escape_string along with your other input cleansing
functions.

Closed Thread


Similar Threads
Thread Thread Starter Forum Replies Last Post
Noob:VB help calling a control to open the database window kennyrogersjr answers 5 May 4th, 2007 03:45 PM
nooB PhP login using MySQL Ben answers 9 March 30th, 2007 10:55 AM
Basic OOP question - why abstract? jason@cyberpine.com answers 7 September 12th, 2006 10:35 PM
asp.net 2.0 membership ASPNETDB_TMP.MDF" is on a network path that is not supported for database files jason@cyberpine.com answers 3 August 25th, 2006 04:55 PM